Skip to content

Commit a7b5c63

Browse files
authored
Merge pull request #3025 from ales-erjavec/combo-box-popup-block-mouse-release
[FIX] gui: Suppress mouse button release on the combo box popup
2 parents 1289011 + 857ff5b commit a7b5c63

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

Orange/widgets/gui.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
import pkg_resources
1616

1717
from AnyQt import QtWidgets, QtCore, QtGui
18-
from AnyQt.QtCore import Qt, QSize, QItemSelection, pyqtSignal as Signal
18+
# pylint: disable=unused-import
19+
from AnyQt.QtCore import (
20+
Qt, QObject, QEvent, QSize, QItemSelection, QTimer, pyqtSignal as Signal
21+
)
1922
from AnyQt.QtGui import QCursor, QColor
2023
from AnyQt.QtWidgets import (
2124
QApplication, QStyle, QSizePolicy, QWidget, QLabel, QGroupBox, QSlider,
22-
QComboBox, QLineEdit, QVBoxLayout, QHBoxLayout,
23-
QTableWidget, QTableWidgetItem, QItemDelegate, QStyledItemDelegate,
25+
QComboBox, QTableWidgetItem, QItemDelegate, QStyledItemDelegate,
2426
QTableView, QHeaderView, QListView
2527
)
2628

@@ -1506,10 +1508,15 @@ def __init__(self, parent=None, maximumContentsLength=-1, **kwargs):
15061508
# Forward-declared for sizeHint()
15071509
self.__maximumContentsLength = maximumContentsLength
15081510
super().__init__(parent, **kwargs)
1511+
1512+
self.__in_mousePressEvent = False
1513+
# Yet Another Mouse Release Ignore Timer
1514+
self.__yamrit = QTimer(self, singleShot=True)
15091515
view = self.view()
15101516
# optimization for displaying large models
15111517
if isinstance(view, QListView):
15121518
view.setUniformItemSizes(True)
1519+
view.viewport().installEventFilter(self)
15131520

15141521
def setMaximumContentsLength(self, length):
15151522
"""
@@ -1556,6 +1563,29 @@ def minimumSizeHint(self):
15561563
sh = sh.boundedTo(QtCore.QSize(width, sh.height()))
15571564
return sh
15581565

1566+
# workaround for QTBUG-67583
1567+
def mousePressEvent(self, event):
1568+
# reimplemented
1569+
self.__in_mousePressEvent = True
1570+
super().mousePressEvent(event)
1571+
self.__in_mousePressEvent = False
1572+
1573+
def showPopup(self):
1574+
# reimplemented
1575+
super().showPopup()
1576+
if self.__in_mousePressEvent:
1577+
self.__yamrit.start(QApplication.doubleClickInterval())
1578+
1579+
def eventFilter(self, obj, event):
1580+
# type: (QObject, QEvent) -> bool
1581+
if event.type() == QEvent.MouseButtonRelease \
1582+
and event.button() == Qt.LeftButton \
1583+
and obj is self.view().viewport() \
1584+
and self.__yamrit.isActive():
1585+
return True
1586+
else:
1587+
return super().eventFilter(obj, event)
1588+
15591589

15601590
# TODO comboBox looks overly complicated:
15611591
# - can valueType be anything else than str?

0 commit comments

Comments
 (0)