summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcombobox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r--src/widgets/widgets/qcombobox.cpp55
1 files changed, 46 insertions, 9 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index e0bc198d2e..9afb4b3ae6 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -45,6 +45,7 @@
#include <qlineedit.h>
#include <qapplication.h>
#include <qdesktopwidget.h>
+#include <private/qdesktopwidget_p.h>
#include <qlistview.h>
#if QT_CONFIG(tableview)
#include <qtableview.h>
@@ -73,11 +74,6 @@
#include <private/qlineedit_p.h>
#include <private/qcompleter_p.h>
#include <qdebug.h>
-#if 0 /* Used to be included in Qt4 for Q_WS_MAC */ && QT_CONFIG(effetcts) && QT_CONFIG(style_mac)
-#include <private/qcore_mac_p.h>
-#include <private/qmacstyle_mac_p.h>
-#include <private/qt_cocoa_helpers_mac_p.h>
-#endif
#if QT_CONFIG(effects)
# include <private/qeffects_p.h>
#endif
@@ -203,7 +199,21 @@ void QComboBoxPrivate::_q_completerActivated(const QModelIndex &index)
if (index.isValid() && q->completer()) {
QAbstractProxyModel *proxy = qobject_cast<QAbstractProxyModel *>(q->completer()->completionModel());
if (proxy) {
- q->setCurrentIndex(proxy->mapToSource(index).row());
+ const QModelIndex &completerIndex = proxy->mapToSource(index);
+ int row = -1;
+ if (completerIndex.model() == model) {
+ row = completerIndex.row();
+ } else {
+ // if QCompleter uses a proxy model to host widget's one - map again
+ QAbstractProxyModel *completerProxy = qobject_cast<QAbstractProxyModel *>(q->completer()->model());
+ if (completerProxy && completerProxy->sourceModel() == model) {
+ row = completerProxy->mapToSource(completerIndex).row();
+ } else {
+ QString match = q->completer()->model()->data(completerIndex).toString();
+ row = q->findText(match, matchFlags());
+ }
+ }
+ q->setCurrentIndex(row);
emitActivated(currentIndex);
}
}
@@ -256,8 +266,8 @@ QRect QComboBoxPrivate::popupGeometry(int screen) const
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme())
useFullScreenForPopupMenu = theme->themeHint(QPlatformTheme::UseFullScreenForPopupMenu).toBool();
return useFullScreenForPopupMenu ?
- QApplication::desktop()->screenGeometry(screen) :
- QApplication::desktop()->availableGeometry(screen);
+ QDesktopWidgetPrivate::screenGeometry(screen) :
+ QDesktopWidgetPrivate::availableGeometry(screen);
}
bool QComboBoxPrivate::updateHoverControl(const QPoint &pos)
@@ -418,6 +428,20 @@ void QComboBoxPrivateContainer::resizeEvent(QResizeEvent *e)
QFrame::resizeEvent(e);
}
+void QComboBoxPrivateContainer::paintEvent(QPaintEvent *e)
+{
+ QStyleOptionComboBox cbOpt = comboStyleOption();
+ if (combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &cbOpt, combo)
+ && mask().isEmpty()) {
+ QStyleOption opt;
+ opt.initFrom(this);
+ QPainter p(this);
+ style()->drawPrimitive(QStyle::PE_PanelMenu, &opt, &p, this);
+ }
+
+ QFrame::paintEvent(e);
+}
+
void QComboBoxPrivateContainer::leaveEvent(QEvent *)
{
// On Mac using the Mac style we want to clear the selection
@@ -487,6 +511,14 @@ void QComboBoxPrivateContainer::scrollItemView(int action)
#endif
}
+void QComboBoxPrivateContainer::hideScrollers()
+{
+ if (top)
+ top->hide();
+ if (bottom)
+ bottom->hide();
+}
+
/*
Hides or shows the scrollers when we emulate a popupmenu
*/
@@ -2612,7 +2644,7 @@ void QComboBox::showPopup()
QComboBoxPrivateContainer* container = d->viewContainer();
QRect listRect(style->subControlRect(QStyle::CC_ComboBox, &opt,
QStyle::SC_ComboBoxListBoxPopup, this));
- QRect screen = d->popupGeometry(QApplication::desktop()->screenNumber(this));
+ QRect screen = d->popupGeometry(QDesktopWidgetPrivate::screenNumber(this));
QPoint below = mapToGlobal(listRect.bottomLeft());
int belowHeight = screen.bottom() - below.y();
@@ -2747,6 +2779,11 @@ void QComboBox::showPopup()
if (needHorizontalScrollBar) {
listRect.adjust(0, 0, 0, sb->height());
}
+
+ // Hide the scrollers here, so that the listrect gets the full height of the container
+ // If the scrollers are truly needed, the later call to container->updateScrollers()
+ // will make them visible again.
+ container->hideScrollers();
container->setGeometry(listRect);
#ifndef Q_OS_MAC