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)
def eventFilter(self, obj: QObject, event: QEvent): if event.type() == QEvent.MouseButtonPress: if not self.playlistDialog.isHidden(): self.playlistDialog.hide() # 1. 如果主窗口被激活, 关闭子窗口 if event.type() == QEvent.WindowActivate: if not self.playlistDialog.isHidden(): self.playlistDialog.hide() # 2. 如果左下缩放按钮被鼠标左键拖动, 则缩放窗口 if obj == self.btn_zoom and event.type( ) == QEvent.MouseMove and event.buttons() == Qt.LeftButton: width = event.globalX() - self.x() height = event.globalY() - self.y() self.setGeometry(self.x(), self.y(), width, height) if obj == self.header and type( event) == QMouseEvent and event.buttons() == Qt.LeftButton: # 如果标题栏被双击 if event.type() == QEvent.MouseButtonDblClick: self.showMaximizedNormal() # 记录拖动标题栏的位置 elif event.type() == QEvent.MouseButtonPress: self.point = event.globalPos() - self.frameGeometry().topLeft() # 如果标题栏被拖动 elif event.type() == QEvent.MouseMove: if self.windowState() == Qt.WindowNoState: self.move(event.globalPos() - self.point) # 3. 当鼠标移动到music_image时显示遮罩层 if obj == 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 obj == self.music_image_label: if event.type() == QEvent.Leave: self.music_image_label.hide() if event.type() == QEvent.MouseButtonPress: self.change2playPage() # 4. if obj == self.label_lyric: if event.type() == QEvent.Wheel: self.is_wheeling = True else: self.is_wheeling = False return super().eventFilter(obj, event)