Ejemplo n.º 1
0
    def eventFilter(self, source, event: QtCore.QEvent):
        if source is self._scene:
            if event.type() == QtCore.QEvent.GraphicsSceneMouseRelease and\
               event.button() == QtCore.Qt.LeftButton and\
               event.scenePos().x() >= 0 and event.scenePos().x() < self._scene.width() and\
               event.scenePos().y() >= 0 and event.scenePos().y() < self._scene.height():

                pos = event.scenePos()
                box_clicked_x = self.windowToSquareX(pos.x())
                box_clicked_y = self.windowToSquareYInv(pos.y())
                new_origin = int(box_clicked_x +
                                 box_clicked_y * self.hor_pixels)

                if not self.shift_down:
                    self.curr_origins.clear()

                self.curr_origins.add(new_origin)
                print(self.curr_origins)
                self.originsUpdated.emit(self.curr_origins)

            elif event.type() == QtCore.QEvent.GraphicsSceneMouseMove:
                self.onMouseHover(event.scenePos())

            elif event.type() == QtCore.QEvent.KeyPress:
                if event.key() == QtCore.Qt.Key_Shift:
                    self.shift_down = True

            elif event.type() == QtCore.QEvent.KeyRelease:
                if event.key() == QtCore.Qt.Key_Shift:
                    self.shift_down = False
        return widgets.QWidget.eventFilter(self, source, event)
Ejemplo n.º 2
0
    def editorEvent(
        self,
        event: QtCore.QEvent,
        model: QtCore.QAbstractItemModel,
        option: QStyleOptionViewItem,
        index: QtCore.QModelIndex,
    ) -> bool:
        if not (index.flags() & Qt.ItemIsEditable) != 0:
            return False

        if event.type() == QEvent.MouseButtonRelease or event.type(
        ) == QEvent.MouseButtonDblClick:
            if event.button() != Qt.LeftButton or not self.get_checkbox_rect(
                    option).contains(event.pos()):
                return False
            if event.type() == QEvent.MouseButtonDblClick:
                return True
        elif event.type() == QEvent.KeyPress:
            if event.key() != Qt.Key_Space and event.key() != Qt.Key_Select:
                return False
        else:
            return False

        self.setModelData(None, model, index)
        return True
Ejemplo n.º 3
0
 def eventFilter(self, obj: QObject, event: QEvent) -> bool:
     if event.type() == QEvent.Enter:
         qApp.setOverrideCursor(Qt.PointingHandCursor)
     elif event.type() == QEvent.Leave:
         qApp.restoreOverrideCursor()
     return super(ClipErrorsDialog.VCToolBox,
                  self).eventFilter(obj, event)
Ejemplo n.º 4
0
 def eventFilter(self, widget: QObject, event: QEvent):
     if event.type() == QEvent.ShowToParent and not self._visible:
         self._visible = True
         self.visibilityChanged.emit(True)
     elif event.type() == QEvent.HideToParent and self._visible:
         self.checkAllWidgets()
     return super().eventFilter(widget, event)
Ejemplo n.º 5
0
 def _checkLineEditEvent(self, evt: QEvent) -> bool:
     if evt.type() == QEvent.MouseButtonPress:
         return True
     if evt.type() == QEvent.KeyPress:
         if evt.key() == Qt.Key_Return or evt.key() == Qt.Key_Space or evt.key() == Qt.Key_Enter:
             return True
     return False
Ejemplo n.º 6
0
 def eventFilter(self, obj, e: QEvent):
     """ 过滤事件 """
     if obj == self.navigationInterface.navigationMenu:
         # 显示导航菜单是更改标题栏返回按钮和标题的父级为导航菜单
         isVisible = self.titleBar.returnBt.isVisible()
         if e.type() == QEvent.Show:
             self.titleBar.returnBt.setParent(obj)
             # 显示标题
             self.titleBar.title.setParent(obj)
             self.titleBar.title.move(15, 10)
             self.titleBar.title.show()
             # 如果播放栏课件就缩短导航菜单
             isScaled = self.playBar.isVisible()
             height = self.height() - isScaled * self.playBar.height()
             self.navigationInterface.navigationMenu.setBottomSpacingVisible(
                 not isScaled)
             self.navigationInterface.navigationMenu.resize(
                 self.navigationInterface.navigationMenu.width(), height)
         elif e.type() == QEvent.Hide:
             # 隐藏标题
             self.titleBar.title.hide()
             self.titleBar.title.setParent(self.titleBar)
             self.titleBar.returnBt.setParent(self.titleBar)
         # 根据情况显示/隐藏返回按钮和标题
         self.titleBar.returnBt.setVisible(isVisible)
     return super().eventFilter(obj, e)
Ejemplo n.º 7
0
 def eventFilter(self, source: QObject, event: QEvent) -> bool:
     if event.type() in {QEvent.Type.KeyPress, QEvent.Type.KeyRelease}:
         assert isinstance(event, (QKeyEvent, QMouseEvent))
         self._update_cursor(event)
     if event.type() in {QEvent.Type.Enter, QEvent.Type.Leave}:
         self._update_cursor(None)
     return False
Ejemplo n.º 8
0
    def eventFilter(self, obj: QObject, event: QEvent):
        """ Implementation of QObject::eventFilter()
            Intercept drag-and-drop events before they are passed to the QTableWidget.
            In response to the drop of a text (.txt or .csv) file, opens that file.

        @param obj: the "watched object" that events are intercepted from (self in our case)
        @param event: the event
        @return: whether the event is accepted or rejected for further processing.
        """

        if event.type() == QEvent.Drop:
            event.accept()
            mime = event.mimeData()
            if mime.hasText():
                file_path = mime.text()
                if file_path.endswith('.txt') or file_path.endswith('.csv'):
                    file_path = file_path.replace('file:///', '')
                    with open(file_path) as reader:
                        rows = reader.readlines()
                        if rows:
                            self.set_row_data(rows)
                            self.parent.setWindowTitle(os.path.basename(file_path))

            return True
        elif event.type() == QEvent.DragEnter:
            event.accept()
            return True
        return False
Ejemplo n.º 9
0
 def event(self, event: QEvent) -> bool:
     if event.type() == QEvent.FocusOut or (
             event.type() == QEvent.MouseButtonPress
             and not self.geometry().contains(event.screenPos().toPoint())):
         # The click was outside of the systray
         self.hide()
     return super().event(event)
Ejemplo n.º 10
0
    def eventFilter(self, obj: QObject, ev: QEvent):
        if obj != self.popup:
            return False

        if ev.type() == QEvent.MouseButtonPress:
            self.popup.hide()
            self.editor.setFocus()
            return True

        if ev.type() == QEvent.KeyPress:
            consumed = False
            ev: QKeyEvent
            key = ev.key()

            if (Qt.Key_Enter == key) or (Qt.Key_Return == key):
                self.doneCompletion()
                consumed = True
            elif Qt.Key_Return == key:
                self.editor.setFocus()
                self.popup.hide()
                consumed = True
            elif (key == Qt.Key_Undo) or (key == Qt.Key_Down) or (
                    key == Qt.Key_Home) or (key == Qt.Key_End) or (
                        key == Qt.Key_PageUp) or (key == Qt.Key_PageDown):
                pass
            else:
                self.editor.setFocus()
                self.editor.event(ev)
                self.popup.hide()
            return consumed
        return False
Ejemplo n.º 11
0
 def eventFilter(self, obj, e: QEvent):
     """ 安装监听 """
     if obj == self:
         if e.type() == QEvent.Enter:
             self.songNameCard.checkBox.show()
             self.songNameCard.buttonGroup.setHidden(self.isInSelectionMode)
             state = "selected-enter" if self.isSelected else "notSelected-enter"
             self.setWidgetState(state)
             self.setStyle(QApplication.style())
         elif e.type() == QEvent.Leave:
             # 不处于选择模式下时,如果歌曲卡没被选中而鼠标离开窗口就隐藏复选框和按钮组窗口
             if not self.isSelected:
                 self.songNameCard.buttonGroup.hide()
                 self.songNameCard.checkBox.setHidden(
                     not self.isInSelectionMode)
             state = "selected-leave" if self.isSelected else "notSelected-leave"
             self.setWidgetState(state)
             self.setStyle(QApplication.style())
         elif e.type() == QEvent.MouseButtonPress:
             state = "selected-pressed" if self.isSelected else "notSelected-pressed"
             if e.button() == Qt.LeftButton:
                 self.isSelected = True
             self.setWidgetState(state)
             self.setStyle(QApplication.style())
         elif e.type() == QEvent.MouseButtonRelease and e.button(
         ) == Qt.LeftButton:
             self.setWidgetState("selected-leave")
             self.setCheckBoxBtLabelState("selected")  # 鼠标松开时将设置标签为白色
             self.setStyle(QApplication.style())
         elif e.type() == QEvent.MouseButtonDblClick:
             self.isDoubleClicked = True
     return super().eventFilter(obj, e)
Ejemplo n.º 12
0
 def event(self, e: QEvent) -> bool:
     logger.info('event - Event of type %s detected.' % e.type())
     if e.type() == QEvent.FileOpen:
         file = e.file()
         logger.info('event - file path is %s' % file)
         if str(file).endswith('.pro6plx'):
             quickstart(file)
     return QApplication.event(appctxt.app, e)
Ejemplo n.º 13
0
 def eventFilter(self, obj, event: QtCore.QEvent):
     if event.type() == QtCore.QEvent.Enter and not self.hovered:
         self.hovered = True
         self.setIcon(self.hoverIcon)
     elif event.type() == QtCore.QEvent.Leave and self.hovered:
         self.hovered = False
         self.setIcon(self.regularIcon)
     return super(Button, self).eventFilter(obj, event)
Ejemplo n.º 14
0
 def eventFilter(
     self, source: QtCore.QObject, event: QtCore.QEvent
 ) -> bool:
     if event.type() in {QtCore.QEvent.KeyPress, QtCore.QEvent.KeyRelease}:
         self._update_cursor(event)
     if event.type() in {QtCore.QEvent.Enter, QtCore.QEvent.Leave}:
         self._update_cursor(None)
     return False
Ejemplo n.º 15
0
 def changeEvent(self, e: QEvent) -> None:
     if e.type() == QEvent.WindowStateChange and self.windowState(
     ) == Qt.WindowMaximized:
         self.horizontal_splitter.setSizes(
             [self.height() - self.downSize, self.downSize])
     elif e.type() == QEvent.WindowStateChange and self.windowState(
     ) == Qt.WindowNoState:
         self.horizontal_splitter.setSizes(
             [self.height() - self.downSize, self.downSize])
 def eventFilter(self, obj:QObject, event:QEvent):
     if obj is self.toolBoxWidget and event.type()==QEvent.Close:
         self.penBoxAction.setChecked(False)
         return True
     if obj is self.plotDockWgt and event.type()==QEvent.Close:
         self.colorGamutAction.setChecked(False)
         return True
     
     return super().eventFilter(obj, event)
Ejemplo n.º 17
0
 def eventFilter(self, obj: QObject, event: QEvent) -> bool:
     if event.type() == QEvent.ToolTip:
         return True
     elif event.type() == QEvent.Enter and obj.isEnabled():
         qApp.setOverrideCursor(Qt.PointingHandCursor)
     elif event.type() == QEvent.Leave:
         qApp.restoreOverrideCursor()
     elif event.type() == QEvent.StatusTip and not obj.isEnabled():
         return True
     return super(VideoToolBar, self).eventFilter(obj, event)
Ejemplo n.º 18
0
    def eventFilter(self, obj: QObject, event: QEvent):
        print(event.type())
        if event.type() == QEvent.MouseMove:
            print("move")
        if event.type() == QEvent.KeyPress:
            print("key presss")
        if event.type() == QEvent.MouseButtonPress:
            print("press")

        return super().eventFilter(obj, event)
Ejemplo n.º 19
0
 def eventFilter(self, obj, e: QEvent):
     """ 过滤事件 """
     if obj == self.checkBox:
         if e.type() == QEvent.Show:
             self.trackNumLabel.hide()
             return False
         elif e.type() == QEvent.Hide:
             self.trackNumLabel.show()
             return False
     return super().eventFilter(obj, e)
Ejemplo n.º 20
0
def widgetEvent(widget: QWidget, e: QtCore.QEvent):
    # All of our widgets should call this in a def event() override
    # to allow for dynamic property changes etc.
    if e.type() == QtCore.QEvent.DynamicPropertyChange:
        if isinstance(e, QtCore.QDynamicPropertyChangeEvent):
            name = e.propertyName().data().decode('utf8')
            if name in ["class"]:
                widgetPropertyChanged(widget)
    elif e.type() == QtCore.QEvent.ReadOnlyChange:
        widgetPropertyChanged(widget)
Ejemplo n.º 21
0
 def eventFilter(self, obj, e: QEvent):
     """ 过滤事件 """
     if obj is self.headPortraitWidget:
         if e.type() == QEvent.Enter:
             self.headPortraitMask.show()
             return False
         elif e.type() == QEvent.Leave:
             self.headPortraitMask.hide()
             return False
     return super().eventFilter(obj, e)
Ejemplo n.º 22
0
    def eventFilter(self, watched: QtCore.QObject,
                    event: QtCore.QEvent) -> bool:
        if watched == self.button1 and event.type(
        ) == QtCore.QEvent.MouseButtonPress:
            print("MouseButtonPress")
        if watched == self.button2 and event.type(
        ) == QtCore.QEvent.MouseButtonDblClick:
            print("MouseButtonDblClick")

        return super(MyEventHandler, self).eventFilter(watched, event)
Ejemplo n.º 23
0
 def eventFilter(self, a0, a1: QtCore.QEvent) -> bool:
     if a1.type() == QtCore.QEvent.FocusIn and a0 is self.text:
         self.findMainWin().mapview.data.begin()
         self.oldTextStore = []
         for x in self.selection():
             self.oldTextStore.append(x.dup())
     if a1.type() == QtCore.QEvent.FocusOut and a0 is self.text:
         for x in self.selection():
             self._getMapData()._appendHistory(self.oldTextStore.pop(0), x)
         self.oldTextStore.clear()
     return super().eventFilter(a0, a1)
Ejemplo n.º 24
0
 def eventFilter(self, obj: QObject, event: QEvent):
     if event.type() == QEvent.DragEnter:
         log.debug('DragEnter')
         self.on_drag_enter(obj, event)
     elif event.type() == QEvent.DragLeave:
         log.debug('DragLeave')
         self.on_drag_leave(obj, event)
     elif event.type() == QEvent.Drop:
         log.debug('Drop')
         self.on_drop(obj, event)
     return QWidget.eventFilter(self, obj, event)
Ejemplo n.º 25
0
    def eventFilter(self, source: QPushButton, event: QEvent) -> QPushButton:
        """
        Override event logic
        FocusIn, FocusOut
        """

        states = {10: True, 11: False}
        if event.type() in states:
            self.enter = states[event.type()]
            self.update()
        return QPushButton.eventFilter(self, source, event)
Ejemplo n.º 26
0
 def eventFilter(self, obj, e: QEvent):
     """ 过滤事件 """
     if obj == self:
         if e.type() == QEvent.Enter:
             self.__isEnter = True
             self.update()
             return False
         elif e.type() == QEvent.Leave:
             self.__isEnter = False
             self.update()
             return False
     return super().eventFilter(obj, e)
Ejemplo n.º 27
0
    def eventFilter(self, obj, event: QtCore.QEvent) -> bool:  # pylint: disable=unused-argument
        if event.type() == QtCore.QEvent.KeyPress:
            if event.key() == QtCore.Qt.Key_Control:
                self._dialog._ctrl_pressed = True
                return True

        elif event.type() == QtCore.QEvent.KeyRelease:
            if event.key() == QtCore.Qt.Key_Control:
                self._dialog._ctrl_pressed = False
                return True

        return False
Ejemplo n.º 28
0
 def eventFilter(self, obj, event: QEvent):
     if event.type() == QEvent.MouseButtonPress:
         print("press")
         return True
     elif event.type() == QEvent.MouseMove:
         o: SchemeWidget = obj.parent()
         o.mouse_move(event)
         return True
     elif event.type() == QEvent.MouseButtonRelease:
         print("release")
         return True
     return False
Ejemplo n.º 29
0
    def eventFilter(self, object: QObject, event: QEvent):
        if event.type() == QEvent.MouseButtonPress:
            pass
        # 1. 如果主窗口被激活, 关闭子窗口
        if event.type() == QEvent.WindowActivate:
            if not self.add_music_list_dialog.isHidden():
                self.add_music_list_dialog.hide()

        # 2. 如果左下缩放按钮被鼠标左键拖动, 则缩放窗口
        if object == self.btn_zoom and event.type(
        ) == QEvent.MouseMove and event.buttons() == Qt.LeftButton:
            global_x = event.globalX()
            global_y = event.globalY()
            window_global_x = self.x()
            window_global_y = self.y()
            width = global_x - window_global_x
            heigth = global_y - window_global_y
            self.setGeometry(window_global_x, window_global_y, width, heigth)
        if object == self.header and type(
                event) == QMouseEvent and event.buttons() == Qt.LeftButton:
            # 如果标题栏被双击
            if event.type() == QEvent.MouseButtonDblClick:
                self.show_maximized_normal()
            # 记录拖动标题栏的位置
            elif event.type() == QEvent.MouseButtonPress:
                self.point = event.globalPos() - self.frameGeometry().topLeft()
            # 如果标题栏被拖动
            elif event.type() == QEvent.MouseMove:
                # print(self.frameGeometry().y())
                # if self.frameGeometry().y() <= 0:
                #     self.show_maximized_normal()
                if self.windowState() == Qt.WindowNoState:
                    self.move(event.globalPos() - self.point)
        # 3. 当鼠标移动到music_image时显示遮罩层
        if object == self.btn_music_image:
            if event.type() == QEvent.Enter:
                self.music_image_label.setGeometry(
                    self.btn_music_image.geometry())
                self.music_image_label.show()
        if object == self.music_image_label:
            if event.type() == QEvent.Leave:
                self.music_image_label.hide()
            if event.type() == QEvent.MouseButtonPress:
                self.change_to_play_page()
        # 4.
        if object == self.label_lyric:
            if event.type() == QEvent.Wheel:
                self.is_wheeling = True
            else:
                self.is_wheeling = False
            # print("eventfilter: " + str(self.is_wheeling))
        return super().eventFilter(object, event)
Ejemplo n.º 30
0
 def eventFilter(self, obj, e: QEvent):
     """ 过滤事件 """
     if obj is self:
         if e.type() in [QEvent.Enter, QEvent.Leave, QEvent.MouseButtonPress, QEvent.MouseButtonRelease]:
             if e.type() in [QEvent.Leave, QEvent.MouseButtonRelease]:
                 self.__state = 'normal'
             elif e.type() == QEvent.Enter:
                 self.__state = 'hover'
             elif e.type() == QEvent.MouseButtonPress:
                 self.__state = 'pressed'
             self.update()
             return False
     return super().eventFilter(obj, e)
Ejemplo n.º 31
0
 def event(self, raw_ev: QEvent) -> bool:
     if raw_ev.type() == QEvent.KeyPress:
         ev = cast(QtGui.QKeyEvent, raw_ev)
         if ev.key() == Qt.Key_Backtab \
                 and ev.modifiers() == Qt.ShiftModifier:
             self.tab_pressed.emit(True)
             return True
         elif ev.key() == Qt.Key_Tab and ev.modifiers() == Qt.NoModifier:
             self.tab_pressed.emit(False)
             return True
     return super().event(raw_ev)
Ejemplo n.º 32
0
 def eventFilter(self_, obj: QtCore.QObject, event: QtCore.QEvent) -> bool:
     if event.type() == QtCore.QEvent.KeyPress:
         key_event = cast(QtGui.QKeyEvent, event)
         actual_key = key_event.key() | int(cast(int, key_event.modifiers()))
         if actual_key in self.settings.key_bindings:
             command_string = self.settings.key_bindings[actual_key]
             self.terminal.exec_command(command_string)
             return True
         elif actual_key == self.settings.terminal_key:
             self.toggle_terminal()
             return True
     return False
Ejemplo n.º 33
0
 def changeEvent(self, evt: QEvent):
     super(XNova_MainWindow, self).changeEvent(evt)
     if evt.type() == QEvent.WindowStateChange:
         if not isinstance(evt, QWindowStateChangeEvent):
             return
         # make sure we only do this for minimize events
         if (evt.oldState() != Qt.WindowMinimized) and self.isMinimized():
             # we were minimized! explicitly hide settings widget
             #     if it is open, otherwise it will be lost forever :(
             if self.settings_widget is not None:
                 if self.settings_widget.isVisible():
                     self.settings_widget.hide()
             # should we minimize to tray?
             if self.cfg['tray']['icon_usage'] == 'show_min':
                 if not self._hidden_to_tray:
                     self._hidden_to_tray = True
                     self.hide()
Ejemplo n.º 34
0
    def event(self, event: QEvent) -> bool:
        if event.type() == _QtFunctionEvent.QtFunctionEvent:
            event._function_event.call()
            return True

        return super().event(event)
Ejemplo n.º 35
0
 def event(self, event: QEvent):
     if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Tab:
         # print("tab pressed")
         return True
     return QGraphicsTextItem.event(self, event)
Ejemplo n.º 36
0
 def eventFilter(self_, obj: QtCore.QObject, event: QtCore.QEvent) -> bool:
     if event.type() == QtCore.QEvent.Close:
         self.settings.save_settings()
     return False
Ejemplo n.º 37
-18
 def event(self, event: QEvent) -> bool:
     if event.type() == QEvent.FocusOut or (
         event.type() == QEvent.MouseButtonPress
         and not self.geometry().contains(event.screenPos().toPoint())
     ):
         # The click was outside of the systray
         self.hide()
     return super().event(event)