|
15 | 15 | import pkg_resources |
16 | 16 |
|
17 | 17 | 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 | +) |
19 | 22 | from AnyQt.QtGui import QCursor, QColor |
20 | 23 | from AnyQt.QtWidgets import ( |
21 | 24 | QApplication, QStyle, QSizePolicy, QWidget, QLabel, QGroupBox, QSlider, |
22 | | - QComboBox, QLineEdit, QVBoxLayout, QHBoxLayout, |
23 | | - QTableWidget, QTableWidgetItem, QItemDelegate, QStyledItemDelegate, |
| 25 | + QComboBox, QTableWidgetItem, QItemDelegate, QStyledItemDelegate, |
24 | 26 | QTableView, QHeaderView, QListView |
25 | 27 | ) |
26 | 28 |
|
@@ -1506,10 +1508,15 @@ def __init__(self, parent=None, maximumContentsLength=-1, **kwargs): |
1506 | 1508 | # Forward-declared for sizeHint() |
1507 | 1509 | self.__maximumContentsLength = maximumContentsLength |
1508 | 1510 | super().__init__(parent, **kwargs) |
| 1511 | + |
| 1512 | + self.__in_mousePressEvent = False |
| 1513 | + # Yet Another Mouse Release Ignore Timer |
| 1514 | + self.__yamrit = QTimer(self, singleShot=True) |
1509 | 1515 | view = self.view() |
1510 | 1516 | # optimization for displaying large models |
1511 | 1517 | if isinstance(view, QListView): |
1512 | 1518 | view.setUniformItemSizes(True) |
| 1519 | + view.viewport().installEventFilter(self) |
1513 | 1520 |
|
1514 | 1521 | def setMaximumContentsLength(self, length): |
1515 | 1522 | """ |
@@ -1556,6 +1563,29 @@ def minimumSizeHint(self): |
1556 | 1563 | sh = sh.boundedTo(QtCore.QSize(width, sh.height())) |
1557 | 1564 | return sh |
1558 | 1565 |
|
| 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 | + |
1559 | 1589 |
|
1560 | 1590 | # TODO comboBox looks overly complicated: |
1561 | 1591 | # - can valueType be anything else than str? |
|
0 commit comments