diff options
author | Frédéric Mercille <fmercille@homer.(none)> | 2009-07-17 12:46:29 (GMT) |
---|---|---|
committer | Olivier Goffart <ogoffart@trolltech.com> | 2009-07-17 13:20:24 (GMT) |
commit | 866e6e6338767086cef8f97bc4e7b38e78b83651 (patch) | |
tree | 81fdb2a2403ef12db4d0305335b65ba14c35ee2a /examples/tools | |
parent | e3a34408aa65af33494b7154ab5eaefe676b5f20 (diff) | |
download | Qt-866e6e6338767086cef8f97bc4e7b38e78b83651.zip Qt-866e6e6338767086cef8f97bc4e7b38e78b83651.tar.gz Qt-866e6e6338767086cef8f97bc4e7b38e78b83651.tar.bz2 |
Lets the size of the completer be configurable in a way similar to QComboBox.
Merge-request: 884
Reviewed-by: Olivier Goffart <ogoffart@trolltech.com>
Diffstat (limited to 'examples/tools')
-rw-r--r-- | examples/tools/completer/mainwindow.cpp | 24 | ||||
-rw-r--r-- | examples/tools/completer/mainwindow.h | 3 |
2 files changed, 23 insertions, 4 deletions
diff --git a/examples/tools/completer/mainwindow.cpp b/examples/tools/completer/mainwindow.cpp index 8ea1c39..06f16de 100644 --- a/examples/tools/completer/mainwindow.cpp +++ b/examples/tools/completer/mainwindow.cpp @@ -75,6 +75,12 @@ MainWindow::MainWindow(QWidget *parent) caseCombo->addItem(tr("Case Insensitive")); caseCombo->addItem(tr("Case Sensitive")); caseCombo->setCurrentIndex(0); + + QLabel *maxVisibleLabel = new QLabel; + maxVisibleLabel->setText(tr("Max Visible Items")); + maxVisibleSpinBox = new QSpinBox; + maxVisibleSpinBox->setRange(3,25); + maxVisibleSpinBox->setValue(10); //! [0] //! [1] @@ -90,6 +96,7 @@ MainWindow::MainWindow(QWidget *parent) connect(modelCombo, SIGNAL(activated(int)), this, SLOT(changeModel())); connect(modeCombo, SIGNAL(activated(int)), this, SLOT(changeMode(int))); connect(caseCombo, SIGNAL(activated(int)), this, SLOT(changeCase(int))); + connect(maxVisibleSpinBox, SIGNAL(valueChanged(int)), this, SLOT(changeMaxVisible(int))); //! [2] //! [3] @@ -99,9 +106,10 @@ MainWindow::MainWindow(QWidget *parent) layout->addWidget(modelLabel, 0, 0); layout->addWidget(modelCombo, 0, 1); layout->addWidget(modeLabel, 1, 0); layout->addWidget(modeCombo, 1, 1); layout->addWidget(caseLabel, 2, 0); layout->addWidget(caseCombo, 2, 1); - layout->addWidget(wrapCheckBox, 3, 0); - layout->addWidget(contentsLabel, 4, 0, 1, 2); - layout->addWidget(lineEdit, 5, 0, 1, 2); + layout->addWidget(maxVisibleLabel, 3, 0); layout->addWidget(maxVisibleSpinBox, 3, 1); + layout->addWidget(wrapCheckBox, 4, 0); + layout->addWidget(contentsLabel, 5, 0, 1, 2); + layout->addWidget(lineEdit, 6, 0, 1, 2); centralWidget->setLayout(layout); setCentralWidget(centralWidget); @@ -205,6 +213,7 @@ void MainWindow::changeModel() { delete completer; completer = new QCompleter(this); + completer->setMaxVisibleItems(maxVisibleSpinBox->value()); switch (modelCombo->currentIndex()) { default: @@ -256,9 +265,16 @@ void MainWindow::changeModel() //! [14] //! [15] +void MainWindow::changeMaxVisible(int max) +{ + completer->setMaxVisibleItems(max); +} +//! [15] + +//! [16] void MainWindow::about() { QMessageBox::about(this, tr("About"), tr("This example demonstrates the " "different features of the QCompleter class.")); } -//! [15] +//! [16] diff --git a/examples/tools/completer/mainwindow.h b/examples/tools/completer/mainwindow.h index f6c962b..30b8d26 100644 --- a/examples/tools/completer/mainwindow.h +++ b/examples/tools/completer/mainwindow.h @@ -52,6 +52,7 @@ class QLabel; class QLineEdit; class QProgressBar; class QCheckBox; +class QSpinBox; QT_END_NAMESPACE //! [0] @@ -67,6 +68,7 @@ private slots: void changeCase(int); void changeMode(int); void changeModel(); + void changeMaxVisible(int); //! [0] //! [1] @@ -77,6 +79,7 @@ private: QComboBox *caseCombo; QComboBox *modeCombo; QComboBox *modelCombo; + QSpinBox *maxVisibleSpinBox; QCheckBox *wrapCheckBox; QCompleter *completer; QLabel *contentsLabel; |