summaryrefslogtreecommitdiffstats
path: root/src/gui/util
diff options
context:
space:
mode:
authorFrédéric Mercille <fmercille@homer.(none)>2009-07-17 12:46:29 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-07-17 13:20:24 (GMT)
commit866e6e6338767086cef8f97bc4e7b38e78b83651 (patch)
tree81fdb2a2403ef12db4d0305335b65ba14c35ee2a /src/gui/util
parente3a34408aa65af33494b7154ab5eaefe676b5f20 (diff)
downloadQt-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 'src/gui/util')
-rw-r--r--src/gui/util/qcompleter.cpp30
-rw-r--r--src/gui/util/qcompleter.h4
-rw-r--r--src/gui/util/qcompleter_p.h1
3 files changed, 32 insertions, 3 deletions
diff --git a/src/gui/util/qcompleter.cpp b/src/gui/util/qcompleter.cpp
index d68e309..bf1fa6a 100644
--- a/src/gui/util/qcompleter.cpp
+++ b/src/gui/util/qcompleter.cpp
@@ -134,7 +134,7 @@
To provide completions, QCompleter needs to know the path from an index.
This is provided by pathFromIndex(). The default implementation of
- pathFromIndex(), returns the data for the \l{Qt::EditRole}{edit role}
+ pathFromIndex(), returns the data for the \l{Qt::EditRole}{edit role}
for list models and the absolute file path if the mode is a QDirModel.
\sa QAbstractItemModel, QLineEdit, QComboBox, {Completer Example}
@@ -772,7 +772,7 @@ QMatchData QUnsortedModelEngine::filter(const QString& part, const QModelIndex&
///////////////////////////////////////////////////////////////////////////////
QCompleterPrivate::QCompleterPrivate()
: widget(0), proxy(0), popup(0), cs(Qt::CaseSensitive), role(Qt::EditRole), column(0),
- sorting(QCompleter::UnsortedModel), wrap(true), eatFocusOut(true)
+ sorting(QCompleter::UnsortedModel), wrap(true), maxVisibleItems(7), eatFocusOut(true)
{
}
@@ -861,7 +861,7 @@ void QCompleterPrivate::showPopup(const QRect& rect)
Qt::LayoutDirection dir = widget->layoutDirection();
QPoint pos;
int rw, rh, w;
- int h = (popup->sizeHintForRow(0) * qMin(7, popup->model()->rowCount()) + 3) + 3;
+ int h = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, popup->model()->rowCount()) + 3) + 3;
QScrollBar *hsb = popup->horizontalScrollBar();
if (hsb && hsb->isVisible())
h += popup->horizontalScrollBar()->sizeHint().height();
@@ -1510,6 +1510,30 @@ bool QCompleter::wrapAround() const
}
/*!
+ \property QCompleter::maxVisibleItems
+ \brief the maximum allowed size on screen of the completer, measured in items
+ \since 4.6
+
+ By default, this property has a value of 7.
+*/
+int QCompleter::maxVisibleItems() const
+{
+ Q_D(const QCompleter);
+ return d->maxVisibleItems;
+}
+
+void QCompleter::setMaxVisibleItems(int maxItems)
+{
+ Q_D(QCompleter);
+ if (maxItems < 0) {
+ qWarning("QCompleter::setMaxVisibleItems: "
+ "Invalid max visible items (%d) must be >= 0", maxItems);
+ return;
+ }
+ d->maxVisibleItems = maxItems;
+}
+
+/*!
\property QCompleter::caseSensitivity
\brief the case sensitivity of the matching
diff --git a/src/gui/util/qcompleter.h b/src/gui/util/qcompleter.h
index c1169ef..a419154 100644
--- a/src/gui/util/qcompleter.h
+++ b/src/gui/util/qcompleter.h
@@ -69,6 +69,7 @@ class Q_GUI_EXPORT QCompleter : public QObject
Q_PROPERTY(CompletionMode completionMode READ completionMode WRITE setCompletionMode)
Q_PROPERTY(int completionColumn READ completionColumn WRITE setCompletionColumn)
Q_PROPERTY(int completionRole READ completionRole WRITE setCompletionRole)
+ Q_PROPERTY(int maxVisibleItems READ maxVisibleItems WRITE setMaxVisibleItems)
Q_PROPERTY(Qt::CaseSensitivity caseSensitivity READ caseSensitivity WRITE setCaseSensitivity)
Q_PROPERTY(bool wrapAround READ wrapAround WRITE setWrapAround)
@@ -118,6 +119,9 @@ public:
bool wrapAround() const;
+ int maxVisibleItems() const;
+ void setMaxVisibleItems(int maxItems);
+
int completionCount() const;
bool setCurrentRow(int row);
int currentRow() const;
diff --git a/src/gui/util/qcompleter_p.h b/src/gui/util/qcompleter_p.h
index dc4189f..288f531 100644
--- a/src/gui/util/qcompleter_p.h
+++ b/src/gui/util/qcompleter_p.h
@@ -87,6 +87,7 @@ public:
Qt::CaseSensitivity cs;
int role;
int column;
+ int maxVisibleItems;
QCompleter::ModelSorting sorting;
bool wrap;