Qt-interest Archive, January 2008
Solved: QComboBox showPopup() in QItemDelegate::setEditorData()
Message 1 in thread
I found a workaround for my problem, originally posted here:
http://lists.trolltech.com/qt-interest/2007-12/thread00777-0.html
The solution is to *not* use QComboBox::showPopup() at all, because it
has a bug that makes it think (in this case) that the mouse button has
been held down long enough to warrant selecting the highlighted item on
mouse *release* (like it normally does it you press, select, release).
To work around it, don't use showPopup(), but rather send it a mouse
press event followed by a mouse release event, like this:
QMouseEvent event1(QEvent::MouseButtonPress, QPoint(0,0),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QMouseEvent event2(QEvent::MouseButtonRelease, QPoint(0,0),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QApplication::sendEvent(comboBox, &event1);
QApplication::sendEvent(comboBox, &event2);
That fixes the problem for me, mostly. The popup still does not get
focus, so the highlighted item appears gray rather than than blue (or
whatever your style shows for selected, but not focused, combo box items
in the popup), because the popup doesn't appear to get focus like it
normally does when you click on a QComboBox.
Nevertheless, this hack works and doesn't force the user to give an
extra click.
Hope this helps.
--Dave
--
[ signature omitted ]