diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2011-07-10 15:24:15 -0500 |
commit | bd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch) | |
tree | 7a520322212d48ebcb9fbe1087e7fca28b76185c /examples/listbox | |
download | qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip |
Add Qt3 development HEAD version
Diffstat (limited to 'examples/listbox')
-rw-r--r-- | examples/listbox/listbox.cpp | 193 | ||||
-rw-r--r-- | examples/listbox/listbox.doc | 29 | ||||
-rw-r--r-- | examples/listbox/listbox.h | 47 | ||||
-rw-r--r-- | examples/listbox/listbox.pro | 11 | ||||
-rw-r--r-- | examples/listbox/main.cpp | 23 |
5 files changed, 303 insertions, 0 deletions
diff --git a/examples/listbox/listbox.cpp b/examples/listbox/listbox.cpp new file mode 100644 index 0000000..60fb1ed --- /dev/null +++ b/examples/listbox/listbox.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. 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 "listbox.h" + +#include <qlabel.h> +#include <qradiobutton.h> +#include <qcheckbox.h> +#include <qspinbox.h> +#include <qlistbox.h> +#include <qbuttongroup.h> +#include <qlayout.h> +#include <qpushbutton.h> + + +ListBoxDemo::ListBoxDemo() + : QWidget( 0, 0 ) +{ + QGridLayout * g = new QGridLayout( this, 2, 2, 6 ); + + g->addWidget( new QLabel( "<b>Configuration:</b>", this ), 0, 0 ); + g->addWidget( new QLabel( "<b>Result:</b>", this ), 0, 1 ); + + l = new QListBox( this ); + g->addWidget( l, 1, 1 ); + l->setFocusPolicy( QWidget::StrongFocus ); + + QVBoxLayout * v = new QVBoxLayout; + g->addLayout( v, 1, 0 ); + + QRadioButton * b; + bg = new QButtonGroup( 0 ); + + b = new QRadioButton( "Fixed number of columns,\n" + "as many rows as needed.", + this ); + bg->insert( b ); + v->addWidget( b ); + b->setChecked( TRUE ); + connect( b, SIGNAL(clicked()), this, SLOT(setNumCols()) ); + QHBoxLayout * h = new QHBoxLayout; + v->addLayout( h ); + h->addSpacing( 30 ); + h->addSpacing( 100 ); + h->addWidget( new QLabel( "Columns:", this ) ); + columns = new QSpinBox( this ); + h->addWidget( columns ); + + v->addSpacing( 12 ); + + b = new QRadioButton( "As many columns as fit on-screen,\n" + "as many rows as needed.", + this ); + bg->insert( b ); + v->addWidget( b ); + connect( b, SIGNAL(clicked()), this, SLOT(setColsByWidth()) ); + + v->addSpacing( 12 ); + + b = new QRadioButton( "Fixed number of rows,\n" + "as many columns as needed.", + this ); + bg->insert( b ); + v->addWidget( b ); + connect( b, SIGNAL(clicked()), this, SLOT(setNumRows()) ); + h = new QHBoxLayout; + v->addLayout( h ); + h->addSpacing( 30 ); + h->addSpacing( 100 ); + h->addWidget( new QLabel( "Rows:", this ) ); + rows = new QSpinBox( this ); + rows->setEnabled( FALSE ); + h->addWidget( rows ); + + v->addSpacing( 12 ); + + b = new QRadioButton( "As many rows as fit on-screen,\n" + "as many columns as needed.", + this ); + bg->insert( b ); + v->addWidget( b ); + connect( b, SIGNAL(clicked()), this, SLOT(setRowsByHeight()) ); + + v->addSpacing( 12 ); + + QCheckBox * cb = new QCheckBox( "Variable-height rows", this ); + cb->setChecked( TRUE ); + connect( cb, SIGNAL(toggled(bool)), this, SLOT(setVariableHeight(bool)) ); + v->addWidget( cb ); + v->addSpacing( 6 ); + + cb = new QCheckBox( "Variable-width columns", this ); + connect( cb, SIGNAL(toggled(bool)), this, SLOT(setVariableWidth(bool)) ); + v->addWidget( cb ); + + cb = new QCheckBox( "Extended-Selection", this ); + connect( cb, SIGNAL(toggled(bool)), this, SLOT(setMultiSelection(bool)) ); + v->addWidget( cb ); + + QPushButton *pb = new QPushButton( "Sort ascending", this ); + connect( pb, SIGNAL( clicked() ), this, SLOT( sortAscending() ) ); + v->addWidget( pb ); + + pb = new QPushButton( "Sort descending", this ); + connect( pb, SIGNAL( clicked() ), this, SLOT( sortDescending() ) ); + v->addWidget( pb ); + + v->addStretch( 100 ); + + int i = 0; + while( ++i <= 2560 ) + l->insertItem( QString::fromLatin1( "Item " ) + QString::number( i ), + i ); + columns->setRange( 1, 256 ); + columns->setValue( 1 ); + rows->setRange( 1, 256 ); + rows->setValue( 256 ); + + connect( columns, SIGNAL(valueChanged(int)), this, SLOT(setNumCols()) ); + connect( rows, SIGNAL(valueChanged(int)), this, SLOT(setNumRows()) ); +} + + +ListBoxDemo::~ListBoxDemo() +{ + delete bg; +} + + +void ListBoxDemo::setNumRows() +{ + columns->setEnabled( FALSE ); + rows->setEnabled( TRUE ); + l->setRowMode( rows->value() ); +} + + +void ListBoxDemo::setNumCols() +{ + columns->setEnabled( TRUE ); + rows->setEnabled( FALSE ); + l->setColumnMode( columns->value() ); +} + + +void ListBoxDemo::setRowsByHeight() +{ + columns->setEnabled( FALSE ); + rows->setEnabled( FALSE ); + l->setRowMode( QListBox::FitToHeight ); +} + + +void ListBoxDemo::setColsByWidth() +{ + columns->setEnabled( FALSE ); + rows->setEnabled( FALSE ); + l->setColumnMode( QListBox::FitToWidth ); +} + + +void ListBoxDemo::setVariableWidth( bool b ) +{ + l->setVariableWidth( b ); +} + + +void ListBoxDemo::setVariableHeight( bool b ) +{ + l->setVariableHeight( b ); +} + +void ListBoxDemo::setMultiSelection( bool b ) +{ + l->clearSelection(); + l->setSelectionMode( b ? QListBox::Extended : QListBox::Single ); +} + +void ListBoxDemo::sortAscending() +{ + l->sort( TRUE ); +} + +void ListBoxDemo::sortDescending() +{ + l->sort( FALSE ); +} diff --git a/examples/listbox/listbox.doc b/examples/listbox/listbox.doc new file mode 100644 index 0000000..eefc2a4 --- /dev/null +++ b/examples/listbox/listbox.doc @@ -0,0 +1,29 @@ +/* +*/ +/*! \page listbox-example.html + + \ingroup examples + \title Listbox Example + + This example shows how to use the different modes (single columns, multiple columns, + fixed number of rows, etc.) of QListBox. + + <hr> + + Header file: + + \include listbox/listbox.h + + <hr> + + Implementation: + + \include listbox/listbox.cpp + + <hr> + + Main: + + \include listbox/main.cpp +*/ + diff --git a/examples/listbox/listbox.h b/examples/listbox/listbox.h new file mode 100644 index 0000000..3eb7d88 --- /dev/null +++ b/examples/listbox/listbox.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. 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 LISTBOX_H +#define LISTBOX_H + + +class QSpinBox; +class QListBox; +class QButtonGroup; + +#include <qwidget.h> + + +class ListBoxDemo: public QWidget +{ + Q_OBJECT +public: + ListBoxDemo(); + ~ListBoxDemo(); + +private slots: + void setNumRows(); + void setNumCols(); + void setRowsByHeight(); + void setColsByWidth(); + void setVariableWidth( bool ); + void setVariableHeight( bool ); + void setMultiSelection( bool ); + void sortAscending(); + void sortDescending(); + +private: + QListBox * l; + QSpinBox * columns; + QSpinBox * rows; + QButtonGroup * bg; +}; + + +#endif diff --git a/examples/listbox/listbox.pro b/examples/listbox/listbox.pro new file mode 100644 index 0000000..b65571a --- /dev/null +++ b/examples/listbox/listbox.pro @@ -0,0 +1,11 @@ +TEMPLATE = app +TARGET = listbox + +CONFIG += qt warn_on release +DEPENDPATH = ../../include + +REQUIRES = large-config + +HEADERS = listbox.h +SOURCES = listbox.cpp \ + main.cpp diff --git a/examples/listbox/main.cpp b/examples/listbox/main.cpp new file mode 100644 index 0000000..c74c498 --- /dev/null +++ b/examples/listbox/main.cpp @@ -0,0 +1,23 @@ +/**************************************************************************** +** +** Copyright (C) 1992-2008 Trolltech ASA. 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 "listbox.h" +#include <qapplication.h> + +int main( int argc, char **argv ) +{ + QApplication a( argc, argv ); + + ListBoxDemo t; + t.setCaption( "Qt Example - Listbox" ); + a.setMainWidget( &t ); + t.show(); + + return a.exec(); +} |