Listviews with Checkable ItemsThis example program shows how to use Listviews with different types of checkable Items. Header file: /**************************************************************************** ** $Id: //depot/qt/main/examples/checklists/checklists.h#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. ** *****************************************************************************/ #ifndef CHECKLISTS_H #define CHECKLISTS_H #include <qwidget.h> class QListView; class QLabel; class CheckLists : public QWidget { Q_OBJECT public: CheckLists( QWidget *parent = 0, const char *name = 0 ); protected: QListView *lv1, *lv2; QLabel *label; protected slots: void copy1to2(); void copy2to3(); }; #endif Implementation: /**************************************************************************** ** $Id: //depot/qt/main/examples/checklists/checklists.cpp#3 $ ** ** 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 "checklists.h" #include <qlistview.h> #include <qvbox.h> #include <qlabel.h> #include <qvaluelist.h> #include <qstring.h> #include <qpushbutton.h> #include <qlayout.h> /* * Constructor * * Create all child widgets of the CheckList Widget */ CheckLists::CheckLists( QWidget *parent, const char *name ) : QWidget( parent, name ) { QHBoxLayout *lay = new QHBoxLayout( this ); lay->setMargin( 5 ); // create a widget which layouts its childs in a column QVBoxLayout *vbox1 = new QVBoxLayout( lay ); vbox1->setMargin( 5 ); // First child: a Label vbox1->addWidget( new QLabel( "Check some items!", this ) ); // Second child: the ListView lv1 = new QListView( this ); vbox1->addWidget( lv1 ); lv1->addColumn( "Items" ); lv1->setRootIsDecorated( TRUE ); // create a list with 4 ListViewItems which will be parent items of other ListViewItems QValueList<QListViewItem *> parentList; parentList.append( new QListViewItem( lv1, "Parent Item 1" ) ); parentList.append( new QListViewItem( lv1, "Parent Item 2" ) ); parentList.append( new QListViewItem( lv1, "Parent Item 3" ) ); parentList.append( new QListViewItem( lv1, "Parent Item 4" ) ); QListViewItem *item = 0; unsigned int num = 1; // go through the list of parent items... for ( QValueList<QListViewItem*>::Iterator it = parentList.begin(); it != parentList.end(); ( *it )->setOpen( TRUE ), ++it, num++ ) { item = *it; // ...and create 5 checkable child ListViewItems for each parent item for ( unsigned int i = 1; i <= 5; i++ ) (void)new QCheckListItem( item, QString( "%1. Child of Parent %2" ).arg( i ).arg( num ), QCheckListItem::CheckBox ); } // Create another widget for layouting QVBoxLayout *tmp = new QVBoxLayout( lay ); tmp->setMargin( 5 ); // create a pushbutton QPushButton *copy1 = new QPushButton( " -> ", this ); tmp->addWidget( copy1 ); copy1->setMaximumWidth( copy1->sizeHint().width() ); // connect the SIGNAL clicked() of the pushbutton with the SLOT copy1to2() connect( copy1, SIGNAL( clicked() ), this, SLOT( copy1to2() ) ); // another widget for layouting QVBoxLayout *vbox2 = new QVBoxLayout( lay ); vbox2->setMargin( 5 ); // and another label vbox2->addWidget( new QLabel( "Check one item!", this ) ); // create the second listview lv2 = new QListView( this ); vbox2->addWidget( lv2 ); lv2->addColumn( "Items" ); lv2->setRootIsDecorated( TRUE ); // another widget needed for layouting only tmp = new QVBoxLayout( lay ); tmp->setMargin( 5 ); // create another pushbutton... QPushButton *copy2 = new QPushButton( " -> ", this ); lay->addWidget( copy2 ); copy2->setMaximumWidth( copy2->sizeHint().width() ); // ...and connect its clicked() SIGNAL to the copy2to3() SLOT connect( copy2, SIGNAL( clicked() ), this, SLOT( copy2to3() ) ); tmp = new QVBoxLayout( lay ); tmp->setMargin( 5 ); // and create a label which will be at the right of the window label = new QLabel( "No Item yet...", this ); tmp->addWidget( label ); } /* * SLOT copy1to2() * * Copies all checked ListViewItems from the first ListView to * the second one, and inserts them as Radio-ListViewItem. */ void Main: /**************************************************************************** ** $Id: //depot/qt/main/examples/checklists/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 "checklists.h" #include < |
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
![]()
![]() Le Qt Labs au hasard![]() Construire l'avenir : (ré-)introduction aux composants de Qt QuickLes 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