summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets
diff options
context:
space:
mode:
authorThorbjørn Lund Martsum <tmartsum@gmail.com>2012-11-25 19:49:53 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-21 21:08:08 +0200
commit7523bbb0c0c023b97144e1e7dd7ccc6c9de32acc (patch)
treeedabfb07146b32f1644b4f06177189bcd4a8bb2c /src/widgets/widgets
parent943ae90744720e6b66a1f05d2a5713a9ad4bd9c6 (diff)
QComboBox - only react on a mouse-release if we had a mousepress
In delegates we get into trouble with calling showPopup in setEditorData (edit by double click) - and that is not reasonable. The user has requested edit - and therefore it is natural to save a click for the user and show the popup at once. However that fails since we have the mouse down and as soon as we release the mouse we will call hidePopup. This patch ensures that the mouseReleaseEvent, that caused the problem is only considered if we have had a mousePressEvent. Change-Id: Ibe031fcb9ad2158f6969e41127bbb5f651b9cae6 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r--src/widgets/widgets/qcombobox.cpp19
-rw-r--r--src/widgets/widgets/qcombobox_p.h4
2 files changed, 21 insertions, 2 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index bdd06da7fc..90310308c3 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -407,7 +407,7 @@ void QComboBoxPrivateContainer::leaveEvent(QEvent *)
}
QComboBoxPrivateContainer::QComboBoxPrivateContainer(QAbstractItemView *itemView, QComboBox *parent)
- : QFrame(parent, Qt::Popup), combo(parent), view(0), top(0), bottom(0)
+ : QFrame(parent, Qt::Popup), combo(parent), view(0), top(0), bottom(0), maybeIgnoreMouseButtonRelease(false)
{
// we need the combobox and itemview
Q_ASSERT(parent);
@@ -667,10 +667,15 @@ bool QComboBoxPrivateContainer::eventFilter(QObject *o, QEvent *e)
}
}
break;
+ case QEvent::MouseButtonPress:
+ maybeIgnoreMouseButtonRelease = false;
+ break;
case QEvent::MouseButtonRelease: {
+ bool ignoreEvent = maybeIgnoreMouseButtonRelease && popupTimer.elapsed() < QApplication::doubleClickInterval();
+
QMouseEvent *m = static_cast<QMouseEvent *>(e);
if (isVisible() && view->rect().contains(m->pos()) && view->currentIndex().isValid()
- && !blockMouseReleaseTimer.isActive()
+ && !blockMouseReleaseTimer.isActive() && !ignoreEvent
&& (view->currentIndex().flags() & Qt::ItemIsEnabled)
&& (view->currentIndex().flags() & Qt::ItemIsSelectable)) {
combo->hidePopup();
@@ -2562,6 +2567,7 @@ void QComboBox::showPopup()
container->setUpdatesEnabled(false);
#endif
+ bool startTimer = !container->isVisible();
container->raise();
container->show();
container->updateScrollers();
@@ -2581,6 +2587,10 @@ void QComboBox::showPopup()
if (QApplication::keypadNavigationEnabled())
view()->setEditFocus(true);
#endif
+ if (startTimer) {
+ container->popupTimer.start();
+ container->maybeIgnoreMouseButtonRelease = true;
+ }
}
/*!
@@ -2876,6 +2886,11 @@ void QComboBox::mousePressEvent(QMouseEvent *e)
}
#endif
showPopup();
+ // The code below ensures that regular mousepress and pick item still works
+ // If it was not called the viewContainer would ignore event since it didn't have
+ // a mousePressEvent first.
+ if (d->viewContainer())
+ d->viewContainer()->maybeIgnoreMouseButtonRelease = false;
} else {
#ifdef QT_KEYPAD_NAVIGATION
if (QApplication::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && d->lineEdit) {
diff --git a/src/widgets/widgets/qcombobox_p.h b/src/widgets/widgets/qcombobox_p.h
index 07ba9b0925..1ad2aa455a 100644
--- a/src/widgets/widgets/qcombobox_p.h
+++ b/src/widgets/widgets/qcombobox_p.h
@@ -254,6 +254,10 @@ private:
QAbstractItemView *view;
QComboBoxPrivateScroller *top;
QComboBoxPrivateScroller *bottom;
+ bool maybeIgnoreMouseButtonRelease;
+ QElapsedTimer popupTimer;
+
+ friend class QComboBox;
};
class QComboMenuDelegate : public QAbstractItemDelegate