Пример #1
0
 def mousePressEvent(self, event):
     if self.mousePressTime.elapsed() < QApplication.doubleClickInterval():
         # Double-click triggers two mouse press events and a double-click event.
         # Ignore the second mouse press event (causes widget's node relocation with
         # Logitech's Smart Move).
         event.ignore()
     else:
         self.mousePressTime.restart()
         if self.shapeItem.path().contains(event.pos()):
             super().mousePressEvent(event)
         else:
             event.ignore()
Пример #2
0
 def mousePressEvent(self, event):
     if self.mousePressTime.elapsed() < QApplication.doubleClickInterval():
         # Double-click triggers two mouse press events and a double-click event.
         # Ignore the second mouse press event (causes widget's node relocation with
         # Logitech's Smart Move).
         event.ignore()
     else:
         self.mousePressTime.restart()
         if self.shapeItem.path().contains(event.pos()):
             super().mousePressEvent(event)
         else:
             event.ignore()
Пример #3
0
 def test_click(self):
     interval = QApplication.doubleClickInterval()
     QApplication.setDoubleClickInterval(0)
     cb = self.cb
     spy = QSignalSpy(cb.activated[int])
     cb.showPopup()
     popup = cb.findChild(QListView)  # type: QListView
     model = popup.model()
     rect = popup.visualRect(model.index(2, 0))
     QTest.mouseRelease(popup.viewport(), Qt.LeftButton, Qt.NoModifier,
                        rect.center())
     QApplication.setDoubleClickInterval(interval)
     self.assertEqual(len(spy), 1)
     self.assertEqual(spy[0], [2])
     self.assertEqual(cb.currentIndex(), 2)
Пример #4
0
 def test_click(self):
     interval = QApplication.doubleClickInterval()
     QApplication.setDoubleClickInterval(0)
     cb = self.cb
     spy = QSignalSpy(cb.activated[int])
     cb.showPopup()
     popup = cb.findChild(QListView)  # type: QListView
     model = popup.model()
     rect = popup.visualRect(model.index(2, 0))
     QTest.mouseRelease(
         popup.viewport(), Qt.LeftButton, Qt.NoModifier, rect.center()
     )
     QApplication.setDoubleClickInterval(interval)
     self.assertEqual(len(spy), 1)
     self.assertEqual(spy[0], [2])
     self.assertEqual(cb.currentIndex(), 2)
Пример #5
0
 def showPopup(self):  # type: () -> None
     # reimplemented
     super().showPopup()
     if self.__in_mousePressEvent:
         self.__yamrit.start(QApplication.doubleClickInterval())
Пример #6
0
    def eventFilter(self, obj, event):  # pylint: disable=too-many-branches
        # type: (QObject, QEvent) -> bool
        """Reimplemented."""
        etype = event.type()
        if etype == QEvent.FocusOut and self.__popup is not None:
            self.hidePopup()
            return True
        if etype == QEvent.Hide and self.__popup is not None:
            self.hidePopup()
            return False

        if etype == QEvent.KeyPress or etype == QEvent.KeyRelease or \
                etype == QEvent.ShortcutOverride and obj is self.__popup:
            event = event  # type: QKeyEvent
            key, modifiers = event.key(), event.modifiers()
            if key in (Qt.Key_Enter, Qt.Key_Return, Qt.Key_Select):
                current = self.__popup.currentIndex()
                if current.isValid():
                    self.__activateProxyIndex(current)
            elif key in (Qt.Key_Up, Qt.Key_Down,
                         Qt.Key_PageUp, Qt.Key_PageDown):
                return False  #
            elif key in (Qt.Key_Tab, Qt.Key_Backtab):
                pass
            elif key == Qt.Key_Escape or \
                    (key == Qt.Key_F4 and modifiers & Qt.AltModifier):
                self.__popup.hide()
                return True
            else:
                # pass the input events to the filter edit line (no propagation
                # up the parent chain).
                self.__searchline.event(event)
                if event.isAccepted():
                    return True
        if etype == QEvent.MouseButtonRelease and self.__popup is not None \
                and obj is self.__popup.viewport() \
                and self.__popupTimer.elapsed() >= \
                    QApplication.doubleClickInterval():
            event = event  # type: QMouseEvent
            index = self.__popup.indexAt(event.pos())
            if index.isValid():
                self.__activateProxyIndex(index)

        if etype == QEvent.MouseMove and self.__popup is not None \
                and obj is self.__popup.viewport():
            event = event  # type: QMouseEvent
            opt = QStyleOptionComboBox()
            self.initStyleOption(opt)
            style = self.style()  # type: QStyle
            if style.styleHint(QStyle.SH_ComboBox_ListMouseTracking, opt, self):
                index = self.__popup.indexAt(event.pos())
                if index.isValid() and \
                        index.flags() & (Qt.ItemIsEnabled | Qt.ItemIsSelectable):
                    self.__popup.setCurrentIndex(index)

        if etype == QEvent.MouseButtonPress and self.__popup is obj:
            # Popup border or out of window mouse button press/release.
            # At least on windows this needs to be handled.
            style = self.style()
            opt = QStyleOptionComboBox()
            self.initStyleOption(opt)
            opt.subControls = QStyle.SC_All
            opt.activeSubControls = QStyle.SC_ComboBoxArrow
            pos = self.mapFromGlobal(event.globalPos())
            sc = style.hitTestComplexControl(QStyle.CC_ComboBox, opt, pos, self)
            if sc != QStyle.SC_None:
                self.__popup.setAttribute(Qt.WA_NoMouseReplay)
            self.hidePopup()

        return super().eventFilter(obj, event)
Пример #7
0
    def eventFilter(self, obj, event):  # pylint: disable=too-many-branches
        # type: (QObject, QEvent) -> bool
        """Reimplemented."""
        etype = event.type()
        if etype == QEvent.FocusOut and self.__popup is not None:
            self.hidePopup()
            return True
        if etype == QEvent.Hide and self.__popup is not None:
            self.hidePopup()
            return False

        if etype == QEvent.KeyPress or etype == QEvent.KeyRelease or \
                etype == QEvent.ShortcutOverride and obj is self.__popup:
            event = event  # type: QKeyEvent
            key, modifiers = event.key(), event.modifiers()
            if key in (Qt.Key_Enter, Qt.Key_Return, Qt.Key_Select):
                current = self.__popup.currentIndex()
                if current.isValid():
                    self.__activateProxyIndex(current)
            elif key in (Qt.Key_Up, Qt.Key_Down,
                         Qt.Key_PageUp, Qt.Key_PageDown):
                return False  #
            elif key in (Qt.Key_Tab, Qt.Key_Backtab):
                pass
            elif key == Qt.Key_Escape or \
                    (key == Qt.Key_F4 and modifiers & Qt.AltModifier):
                self.__popup.hide()
                return True
            else:
                # pass the input events to the filter edit line (no propagation
                # up the parent chain).
                self.__searchline.event(event)
                if event.isAccepted():
                    return True
        if etype == QEvent.MouseButtonRelease and self.__popup is not None \
                and obj is self.__popup.viewport() \
                and self.__popupTimer.elapsed() >= \
                    QApplication.doubleClickInterval():
            event = event  # type: QMouseEvent
            index = self.__popup.indexAt(event.pos())
            if index.isValid():
                self.__activateProxyIndex(index)

        if etype == QEvent.MouseMove and self.__popup is not None \
                and obj is self.__popup.viewport():
            event = event  # type: QMouseEvent
            opt = QStyleOptionComboBox()
            self.initStyleOption(opt)
            style = self.style()  # type: QStyle
            if style.styleHint(QStyle.SH_ComboBox_ListMouseTracking, opt, self):
                index = self.__popup.indexAt(event.pos())
                if index.isValid() and \
                        index.flags() & (Qt.ItemIsEnabled | Qt.ItemIsSelectable):
                    self.__popup.setCurrentIndex(index)

        if etype == QEvent.MouseButtonPress and self.__popup is obj:
            # Popup border or out of window mouse button press/release.
            # At least on windows this needs to be handled.
            style = self.style()
            opt = QStyleOptionComboBox()
            self.initStyleOption(opt)
            opt.subControls = QStyle.SC_All
            opt.activeSubControls = QStyle.SC_ComboBoxArrow
            pos = self.mapFromGlobal(event.globalPos())
            sc = style.hitTestComplexControl(QStyle.CC_ComboBox, opt, pos, self)
            if sc != QStyle.SC_None:
                self.__popup.setAttribute(Qt.WA_NoMouseReplay)
            self.hidePopup()

        return super().eventFilter(obj, event)