Line EditsThe Lineedits example shows how to work with single Lineedit widgets, and how to use different Echo Modes and Validators. Header file: /**************************************************************************** ** $Id: //depot/qt/main/examples/lineedits/lineedits.h#2 $ ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #ifndef LINEDITS_H #define LINEDITS_H #include <qgroupbox.h> class QLineEdit; class QComboBox; class LineEdits : public QGroupBox { Q_OBJECT public: LineEdits( QWidget *parent = 0, const char *name = 0 ); protected: QLineEdit *lined1, *lined2, *lined3, *lined4; QComboBox *combo1, *combo2, *combo3, *combo4; protected slots: void slotEchoChanged( int ); void slotValidatorChanged( int ); void slotAlignmentChanged( int ); void slotReadOnlyChanged( int ); }; #endif Implementation: /**************************************************************************** ** $Id: //depot/qt/main/examples/lineedits/lineedits.cpp#4 $ ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "lineedits.h" #include <qlineedit.h> #include <qcombobox.h> #include <qframe.h> #include <qvalidator.h> #include <qlabel.h> #include <qlayout.h> #include <qhbox.h> /* * Constructor * * Creates child widgets of the LineEdits widget */ LineEdits::LineEdits( QWidget *parent, const char *name ) : QGroupBox( 0, Horizontal, "Line edits", parent, name ) { setMargin( 10 ); QVBoxLayout* box = new QVBoxLayout( layout() ); QHBoxLayout *row1 = new QHBoxLayout( box ); row1->setMargin( 5 ); // Create a Label QLabel* label = new QLabel( "Echo Mode: ", this); row1->addWidget( label ); // Create a Combobox with three items... combo1 = new QComboBox( FALSE, this ); row1->addWidget( combo1 ); combo1->insertItem( "Normal", -1 ); combo1->insertItem( "Password", -1 ); combo1->insertItem( "No Echo", -1 ); // ...and connect the activated() SIGNAL with the slotEchoChanged() SLOT to be able // to react when an item is selected connect( combo1, SIGNAL( activated( int ) ), this, SLOT( slotEchoChanged( int ) ) ); // insert the first LineEdit lined1 = new QLineEdit( this ); box->addWidget( lined1 ); // another widget which is used for layouting QHBoxLayout *row2 = new QHBoxLayout( box ); row2->setMargin( 5 ); // and the second label label = new QLabel( "Validator: ", this ); row2->addWidget( label ); // A second Combobox with again three items... combo2 = new QComboBox( FALSE, this ); row2->addWidget( combo2 ); combo2->insertItem( "No Validator", -1 ); combo2->insertItem( "Integer Validator", -1 ); combo2->insertItem( "Double Validator", -1 ); // ...and again the activated() SIGNAL gets connected with a SLOT connect( combo2, SIGNAL( activated( int ) ), this, SLOT( slotValidatorChanged( int ) ) ); // and the second LineEdit lined2 = new QLineEdit( this ); box->addWidget( lined2 ); // yet another widget which is used for layouting QHBoxLayout *row3 = new QHBoxLayout( box ); row3->setMargin( 5 ); // we need a label for this too label = new QLabel( "Alignment: ", this ); row3->addWidget( label ); // A combo box for setting alignment combo3 = new QComboBox( FALSE, this ); row3->addWidget( combo3 ); combo3->insertItem( "Left", -1 ); combo3->insertItem( "Centered", -1 ); combo3->insertItem( "Right", -1 ); // ...and again the activated() SIGNAL gets connected with a SLOT connect( combo3, SIGNAL( activated( int ) ), this, SLOT( slotAlignmentChanged( int ) ) ); // and the third lineedit lined3 = new QLineEdit( this ); box->addWidget( lined3 ); // last widget used for layouting QHBox *row4 = new QHBox( this ); box->addWidget( row4 ); row4->setMargin( 5 ); // last label (void)new QLabel( "Read-Only: ", row4 ); // A combo box for setting alignment combo4 = new QComboBox( FALSE, row4 ); combo4->insertItem( "False", -1 ); combo4->insertItem( "True", -1 ); // ...and again the activated() SIGNAL gets connected with a SLOT connect( combo4, SIGNAL( activated( int ) ), this, SLOT( slotReadOnlyChanged( int ) ) ); // and the last lineedit lined4 = new QLineEdit( this ); box->addWidget( lined4 ); // give the first LineEdit the focus at the beginning lined1->setFocus(); } /* * SLOT slotEchoChanged( int i ) * * i contains the number of the item which the user has been chosen in the * first Combobox. According to this value, we set the Echo-Mode for the * first LineEdit. */ void Main: /**************************************************************************** ** $Id: //depot/qt/main/examples/lineedits/main.cpp#1 $ ** ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. ** ** This file is part of an example program for Qt. This example ** program may be used, distributed and modified without limitation. ** *****************************************************************************/ #include "lineedits.h" #include < |
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
![]()
![]() Le Qt Labs au hasard![]() Le moteur de rendu OpenVGLes Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.
CommunautéRessources
Liens utilesContact
Qt dans le magazine |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 2.3 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com