def fadeOut(self, callback, distance=-20): duration = 200 self._effects = [] for action in self.actions(): for widget in action.associatedWidgets(): if widget is not self: a = QPropertyAnimation(widget, b"pos", widget) a.setStartValue(widget.pos()) a.setEndValue(widget.pos() + QPoint(0, distance)) self._effects.append(a) a.setDuration(duration) a.setEasingCurve(QEasingCurve.OutBack) a.start(QPropertyAnimation.DeleteWhenStopped) effect = QGraphicsOpacityEffect(self) widget.setGraphicsEffect(effect) self._effects.append(effect) b = QPropertyAnimation(effect, b"opacity") self._effects.append(b) b.setDuration(duration) b.setStartValue(1) b.setEndValue(0) b.setEasingCurve(QEasingCurve.OutBack) b.start(QPropertyAnimation.DeleteWhenStopped) b.finished.connect(partial(self.removeAction, action)) b.finished.connect(callback) if not self.actions(): callback()
def _fade_setup(self): """ """ self._fade_running = True self.effect = QGraphicsOpacityEffect(self) self.setGraphicsEffect(self.effect) self.anim = QPropertyAnimation(self.effect, to_binary_string("opacity"))
def add_flash_animation(widget: QWidget, duration: int = 300, color: Array = (0.5, 0.5, 0.5, 0.5)): """Add flash animation to widget to highlight certain action (e.g. taking a screenshot). Parameters ---------- widget : QWidget Any Qt widget. duration : int Duration of the flash animation. color : Array Color of the flash animation. By default, we use light gray. """ color = transform_color(color)[0] color = (255 * color).astype("int") effect = QGraphicsColorizeEffect(widget) widget.setGraphicsEffect(effect) widget._flash_animation = QPropertyAnimation(effect, b"color") widget._flash_animation.setStartValue(QColor(0, 0, 0, 0)) widget._flash_animation.setEndValue(QColor(0, 0, 0, 0)) widget._flash_animation.setLoopCount(1) # let's make sure to remove the animation from the widget because # if we don't, the widget will actually be black and white. widget._flash_animation.finished.connect( partial(remove_flash_animation, weakref.ref(widget))) widget._flash_animation.start() # now set an actual time for the flashing and an intermediate color widget._flash_animation.setDuration(duration) widget._flash_animation.setKeyValueAt(0.1, QColor(*color))
def unfold_menu(self): """ 展开/收起菜单 通过修改左侧widget的最大宽度来实现,展开时设置为180, 收起时设置为60,刚好是一个图标左右的宽度 """ self.tree_menu_action = QPropertyAnimation(self.widget, b'maximumWidth') self.tree_menu_action.stop() mini_width = 50 start = self.widget.width() if self.widget.width() > mini_width: icon = self.resource.font_icon('ei.chevron-right', color="#d2d2d2") end = mini_width self.menu_is_close = True # 在收缩的时候看看是不是有列表是展开的 # 如果有则先对齐收缩再收缩左侧导航栏 if self.expanded_item: self.expanded_item.setExpanded(False) else: icon = self.resource.font_icon('ei.chevron-left', color="#d2d2d2") end = 180 self.menu_is_close = False self.pushButton_8.setIcon(icon) self.tree_menu_action.setStartValue(start) self.tree_menu_action.setEndValue(end) self.tree_menu_action.setEasingCurve(QEasingCurve.InOutBack) self.tree_menu_action.setDuration(500) self.tree_menu_action.start()
def __init__( self, message: str, severity: Union[ str, NotificationSeverity ] = NotificationSeverity.WARNING, source: Optional[str] = None, actions: ActionSequence = (), ): """[summary] """ super().__init__(None) # FIXME: this does not work with multiple viewers. # we need a way to detect the viewer in which the error occured. for wdg in QApplication.topLevelWidgets(): if isinstance(wdg, QMainWindow): try: # TODO: making the canvas the parent makes it easier to # move/resize, but also means that the notification can get # clipped on the left if the canvas is too small. canvas = wdg.centralWidget().children()[1].canvas.native self.setParent(canvas) canvas.resized.connect(self.move_to_bottom_right) break except Exception: pass self.setupUi() self.setAttribute(Qt.WA_DeleteOnClose) self.setup_buttons(actions) self.setMouseTracking(True) self.severity_icon.setText(NotificationSeverity(severity).as_icon()) self.message.setText(message) if source: self.source_label.setText(f'Source: {source}') self.close_button.clicked.connect(self.close) self.expand_button.clicked.connect(self.toggle_expansion) self.timer = None self.opacity = QGraphicsOpacityEffect() self.setGraphicsEffect(self.opacity) self.opacity_anim = QPropertyAnimation(self.opacity, b"opacity", self) self.geom_anim = QPropertyAnimation(self, b"geometry", self) self.move_to_bottom_right()
def __init__( self, message: str, severity: Union[str, NotificationSeverity] = 'WARNING', source: Optional[str] = None, actions: ActionSequence = (), ): super().__init__() from ..qt_main_window import _QtMainWindow current_window = _QtMainWindow.current() if current_window is not None: canvas = current_window.qt_viewer._canvas_overlay self.setParent(canvas) canvas.resized.connect(self.move_to_bottom_right) self.setupUi() self.setAttribute(Qt.WA_DeleteOnClose) self.setup_buttons(actions) self.setMouseTracking(True) self.severity_icon.setText(NotificationSeverity(severity).as_icon()) self.message.setText(message) if source: self.source_label.setText( trans._('Source: {source}', source=source) ) self.close_button.clicked.connect(self.close) self.expand_button.clicked.connect(self.toggle_expansion) self.timer = QTimer() self.opacity = QGraphicsOpacityEffect() self.setGraphicsEffect(self.opacity) self.opacity_anim = QPropertyAnimation(self.opacity, b"opacity", self) self.geom_anim = QPropertyAnimation(self, b"geometry", self) self.move_to_bottom_right()
def fadeIn(self): self._effects = [] for action in self.actions(): effect = QGraphicsOpacityEffect(self) self._effects.append(effect) for widget in action.associatedWidgets(): if widget is not self: widget.setGraphicsEffect(effect) a = QPropertyAnimation(effect, b"opacity") self._effects.append(a) a.setDuration(1000) a.setStartValue(0) a.setEndValue(1) a.setEasingCurve(QEasingCurve.OutBack) a.start(QPropertyAnimation.DeleteWhenStopped)
def __init__(self): super(TourTestWindow, self).__init__() self.setGeometry(300, 100, 400, 600) self.setWindowTitle('Exploring QMainWindow') self.exit = QAction('Exit', self) self.exit.setStatusTip('Exit program') # create the menu bar menubar = self.menuBar() file_ = menubar.addMenu('&File') file_.addAction(self.exit) # create the status bar self.statusBar() # QWidget or its instance needed for box layout self.widget = QWidget(self) self.button = QPushButton('test') self.button1 = QPushButton('1') self.button2 = QPushButton('2') effect = QGraphicsOpacityEffect(self.button2) self.button2.setGraphicsEffect(effect) self.anim = QPropertyAnimation(effect, to_binary_string("opacity")) self.anim.setStartValue(0.01) self.anim.setEndValue(1.0) self.anim.setDuration(500) lay = QVBoxLayout() lay.addWidget(self.button) lay.addStretch() lay.addWidget(self.button1) lay.addWidget(self.button2) self.widget.setLayout(lay) self.setCentralWidget(self.widget) self.button.clicked.connect(self.action1) self.button1.clicked.connect(self.action2) self.tour = AnimatedTour(self)
def set_switch_animation(self, callback=None, duration=200, start=1, end=0, animation=None): """设置切换效果""" self.fade_out_animation = animation or self.fade_out_animation or QPropertyAnimation( self, b'windowOpacity') while self.signals: key, slot = self.signals.popitem() try: self.fade_out_animation.finished.disconnect(slot) except TypeError: pass self.fade_out_animation.stop() self.fade_out_animation.setDuration(duration) self.fade_out_animation.setStartValue(start) self.fade_out_animation.setEndValue(end) if callback: self.signals.update({id(callback): callback}) self.fade_out_animation.finished.connect(callback) self.fade_out_animation.start()