def closeEvent(self, *args, **kwargs): self.save_settings() # Enable paste of clipboard after termination clipboard = QApplication.clipboard() event = QEvent(QEvent.Clipboard) QApplication.sendEvent(clipboard, event) return QMainWindow.closeEvent(self, *args, **kwargs)
def test_base(self, stack_settings, stack_segmentation1, qtbot): widget = SimpleMeasurements(stack_settings) qtbot.addWidget(widget) stack_settings.set_project_info(stack_segmentation1) widget.show() event = QEvent(QEvent.WindowActivate) QApplication.sendEvent(widget, event) assert widget.measurement_layout.count() > 2 for i in range(2, widget.measurement_layout.count()): chk = widget.measurement_layout.itemAt(i).widget() assert isinstance(chk, QCheckBox) chk.setChecked(True) widget.calculate() assert widget.result_view.rowCount() == widget.measurement_layout.count() - 1 assert widget.result_view.columnCount() == len(stack_settings.segmentation_info.bound_info) + 1
def eventFilter(self, obj, event): if obj == self.tabBar(): if event.type() == QEvent.MouseButtonPress and event.buttons( ) == Qt.LeftButton: # can start tab drag only if mouse is at some tab, not at empty tabbar space if self.tabBar().tabAt(event.pos()) >= 0: self.tabDragCanStart = True else: self.dragCanStart = True elif event.type() == QEvent.MouseButtonRelease: self.tabDragCanStart = False self.dragCanStart = False self.manager.updateDragPosition() elif event.type() == QEvent.MouseMove: self.manager.updateDragPosition() if self.tabDragCanStart: if self.tabBar().rect().contains(event.pos()): return False if event.buttons() != Qt.LeftButton: return False toolWindow = self.currentWidget() if not (toolWindow and self.manager.hasToolWindow(toolWindow)): return False self.tabDragCanStart = False #stop internal tab drag in QTabBar releaseEvent = QtGui.QMouseEvent(QEvent.MouseButtonRelease, event.pos(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) QApplication.sendEvent(self.tabBar(), releaseEvent) self.manager.startDrag([toolWindow]) elif self.dragCanStart: self.check_mouse_move(event) return QTabWidget.eventFilter(self, obj, event)