Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
None
-
5.9.4
-
None
-
Qt: 5.9.4
macOS: 10.11.6
-
a4a730f4cbe63ef14edce6be0dfb50a34eb08255
Description
The QComboBox popup sometimes hides immediately after being displayed. For this to happen the model displayed in the combo box must be sufficiently large and/or slow so that the popup display is somewhat delayed. The QStyle::SH_ComboBox_Popup hint also plays a role (popup menus seem to be slower so this affects them more).
Example code:
#include <QApplication> #include <QComboBox> #include <QStandardItemModel> #include <QString> #include <QStyleFactory> #define N_ITEMS 40000 int main(int argc, char *argv[]) { QApplication a(argc, argv); // a.setStyle(QStyleFactory::create(QString("windows"))); // a.setStyle(QStyleFactory::create(QString("fusion"))); QComboBox *cb = new QComboBox(); QStandardItemModel *model = new QStandardItemModel(); // The limit depends on qt build (e.g. 10000 for debug build // and 40000 for release) for (int i=0; i < N_ITEMS; i++) { QStandardItem *item = new QStandardItem(); item->setText(QString("Item %1").arg(i)); model->appendRow(item); } cb->setModel(model); cb->show(); return a.exec(); }
Run this and click on the combo box (try increasing the N_ITEMS if it is to low to observe the issue)
Might be related to QTBUG-66739
Possible fix:
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 9afb4b3ae6..67a33a6f20 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -3164,10 +3164,11 @@ void QComboBoxPrivate::showPopupFromMouseEvent(QMouseEvent *e) q->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 (viewContainer()) + viewContainer()->blockMouseReleaseTimer.start(QApplication::doubleClickInterval()); viewContainer()->maybeIgnoreMouseButtonRelease = false; } else { #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled() && sc == QStyle::SC_ComboBoxEditField && lineEdit) { lineEdit->event(e); //so lineedit can move cursor, etc
I.e. reset the blockMouseReleaseTimer in QComboBoxPrivate::showPopupFromMouseEvent after the showPopup call so that the layout/size hinting done in showPopup does not count towards the blockMouseReleaseTimer's timeout (but it might be more complicated than that; there are more timers and flags related to mouse release handling)
Attachments
For Gerrit Dashboard: QTBUG-67583 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
228669,3 | QComboBox: Start blockMouseReleaseTimer after showPopup call | dev | qt/qtbase | Status: MERGED | +2 | 0 |