def startButtonAnimation(self): # widget.setPixmap # self.start_button.setPixmap(QtGui.QPixmap("Assets/Background dll/Start.png") # .scaledToHeight(75,Qt.TransformationMode.SmoothTransformation)) # time.sleep(0.1) # self.anim.finished.connect(self.showIngameFrame) # self.anim.start() # self.effect = QGraphicsOpacityEffect() # self.start_button.setGraphicsEffect(self.effect) # # self.anim2 = QPropertyAnimation(self.effect, b"opacity") # self.anim2.setDuration(500) # # self.anim2.setCurrentTime(-100) # self.anim2.setStartValue(1) # self.anim2.setEndValue(1) self.anim_group = QtCore.QParallelAnimationGroup() self.anim_group.addAnimation( self.animateWidgetMove(self.start_button, 0, 300, 1000, QEasingCurve.InOutExpo)) self.anim_group.addAnimation( self.animateWidgetMove(self.exit_button, 0, 100, 1000, QEasingCurve.InOutExpo)) self.anim_group.addAnimation( self.animateWidgetMove(self.logo_label, 0, -400, 1300, QEasingCurve.InBounce)) self.anim_group.finished.connect(self.showIngameFrame) self.anim_group.start()
def animateTurnStatus(self): self.anim_groupstatus = QtCore.QParallelAnimationGroup() # print("MASUK SINI CUIY") self.anim_groupstatus.addAnimation( self.animateWidgetMove(self.status_game_label, 400, 0, 300, QEasingCurve.OutExpo)) self.anim_groupstatus.finished.connect(self._animateTurnStatus2) self.anim_groupstatus.start() pass
def __init__(self, parent=parentUI): # 执行 QWidget 的 __init__ super(export_window, self).__init__(parent) # 从 Ui_Form 继承的方法,可以直接将ui生成出来 self.setupUi(self) # self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) if __name__ == "__main__": self.move(200, 300) else: self.move(parent.pos().x() + 200, parent.pos().y() + 300) # self.show() ################ self.toolButton_extra.pressed.connect(self.on_pressed) self.toggle_animation = QtCore.QParallelAnimationGroup(self) self.checkBox_Verbose.hide() self.checkBox_RenderableOnly.hide() self.checkBox_StripNamespaces.hide() self.checkBox_WriteColorSets.hide() self.checkBox_WriteFaceSets.hide() self.checkBox_WholeFrameGeo.hide() self.checkBox_WriteVisibility.hide() self.checkBox_FilterEulerRotations.hide() self.checkBox_WriteCreases.hide() ################ # list window button self.pushButt_Com_List.clicked.connect(lambda: self.list_win('Com')) self.pushButt_Ass_List.clicked.connect(lambda: self.list_win('Ass')) # export button self.Button_Export.clicked.connect(self.export_button) self.Button_Path.clicked.connect(self.path_button) # component assembly button self.pushButt_Com_AddSel.clicked.connect(self.com_butt_add) self.pushButt_Com_GetSel.clicked.connect(self.com_butt_get) self.pushButt_Com_DelSel.clicked.connect(self.com_butt_del) self.pushButt_Ass_AddSel.clicked.connect(self.ass_butt_add) self.pushButt_Ass_GetSel.clicked.connect(self.ass_butt_get) self.pushButt_Ass_DelSel.clicked.connect(self.ass_butt_del) self.pushButt_proxy.clicked.connect(self.proxy_butt) # root get select button self.pushButt_RootName_GetSel.clicked.connect(self.root_butt) # Options action self.action_Reset.triggered.connect(self.reset_action) self.action_Help.triggered.connect(self.help_action) self.actionLoad.triggered.connect(self.load_action) self.actionSave.triggered.connect(self.save_action)
def resetDivideAiHand(self): self.anim_devide = QtCore.QParallelAnimationGroup() self.anim_devide.addAnimation( self.animateWidgetMove(self.ai_left, -25, 0, 240, QEasingCurve.OutExpo)) self.anim_devide.addAnimation( self.animateWidgetMove(self.ai_right, 25, 0, 240, QEasingCurve.OutExpo)) self.anim_devide.finished.connect(self.changeAllHandImage) self.anim_devide.start()
def slideInWgt(self, newwidget): if self.m_active: return self.m_active = True _now = self.currentIndex() _next = self.indexOf(newwidget) if _now == _next: self.m_active = False return offsetx, offsety = self.frameRect().width(), self.frameRect().height() self.widget(_next).setGeometry(self.frameRect()) if not self.m_direction == QtCore.Qt.Horizontal: if _now < _next: offsetx, offsety = 0, -offsety else: offsetx = 0 else: if _now < _next: offsetx, offsety = -offsetx, 0 else: offsety = 0 pnext = self.widget(_next).pos() pnow = self.widget(_now).pos() self.m_pnow = pnow offset = QtCore.QPoint(offsetx, offsety) self.widget(_next).move(pnext - offset) self.widget(_next).show() self.widget(_next).raise_() anim_group = QtCore.QParallelAnimationGroup( self, finished=self.animationDoneSlot) for index, start, end in zip((_now, _next), (pnow, pnext - offset), (pnow + offset, pnext)): animation = QtCore.QPropertyAnimation( self.widget(index), b"pos", duration=self.m_speed, easingCurve=self.m_animationtype, startValue=start, endValue=end, ) anim_group.addAnimation(animation) self.m_next = _next self.m_now = _now self.m_active = True anim_group.start(QtCore.QAbstractAnimation.DeleteWhenStopped)
def showAgainHomeAnimation(self): self.anim_group = QtCore.QParallelAnimationGroup() self.anim_group.addAnimation( self.animateWidgetMove(self.start_button, 0, -300, 1000, QEasingCurve.InOutExpo)) self.anim_group.addAnimation( self.animateWidgetMove(self.exit_button, 0, -100, 1000, QEasingCurve.InOutExpo)) self.anim_group.addAnimation( self.animateWidgetMove(self.logo_label, 0, 400, 1300, QEasingCurve.InBounce)) self.anim_group.start() pass
def _animateTurnStatus2(self): self.anim_groupstate = QtCore.QParallelAnimationGroup() self.anim_groupstate.addAnimation( self.animateWidgetMove(self.status_game_label, 400, 0, 1000, QEasingCurve.InExpo)) if self.the_game.game_states.player == 1: print("MASUK SINI CUIY11") self.anim_groupstate.finished.connect(self.the_game.playGameAi) else: print("MASUK SINI CUIY") self.anim_groupstate.start() pass
def __init__(self, parent=None, title="QCollapse"): """ QCollapse is a collapsible widget with transition Args: parent (QWidget): parent widget for the QCollapseWidget title (str): Title name for the widget """ super(QCollapse, self).__init__(parent=parent) # create main layout main_layout = QtWidgets.QVBoxLayout(self) main_layout.setSpacing(0) main_layout.setContentsMargins(0, 0, 0, 0) # create arrow button self.arrow_button = QtWidgets.QToolButton() self.arrow_button.setToolButtonStyle( QtCore.Qt.ToolButtonTextBesideIcon) self.arrow_button.setArrowType(QtCore.Qt.RightArrow) self.arrow_button.setText(title) self.arrow_button.setCheckable(True) self.arrow_button.setChecked(False) # create collapsible scroll area. This will reception use layout self.scrool_area = QtWidgets.QScrollArea() self.scrool_area.setFrameStyle(6) self.scrool_area.setMinimumHeight(0) self.scrool_area.setMaximumHeight(0) self.scrool_area.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) # adds widgets to layout main_layout.addWidget(self.arrow_button) main_layout.addWidget(self.scrool_area) # creates animation group self.animation_group = QtCore.QParallelAnimationGroup() # declares property to expand the QCollapse widget self.animation_group.addAnimation(QtCore.QPropertyAnimation( self, "minimumHeight")) self.animation_group.addAnimation(QtCore.QPropertyAnimation( self, "maximumHeight")) # declares property to expand the scroll area widget self.animation_group.addAnimation(QtCore.QPropertyAnimation( self.scrool_area, "maximumHeight")) # adds signal connection self.arrow_button.clicked.connect(self.__run_animation)
def showHandAnimation(self): self.anim_group = QtCore.QParallelAnimationGroup() self.anim_group.addAnimation( self.animateWidgetMove(self.player_left, 0, -300, 1000, QEasingCurve.InOutExpo)) self.anim_group.addAnimation( self.animateWidgetMove(self.player_right, 0, -300, 1000, QEasingCurve.InOutExpo)) self.anim_group.addAnimation( self.animateWidgetMove(self.ai_left, 0, 300, 1000, QEasingCurve.InOutExpo)) self.anim_group.addAnimation( self.animateWidgetMove(self.ai_right, 0, 300, 1000, QEasingCurve.InOutExpo)) self.anim_group.finished.connect(self.showTurnInit) self.anim_group.start()
def __init__(self, title="", parent=None): """ Creates a Widget that can collapse and un-collapse at the click of a toggle button Args: title: Displayed title of the Collapsible Widget parent: Collapsed Widget's parent """ super(CollapsibleWidget, self).__init__(parent) self.toggle_button = QtWidgets.QToolButton(text=title, checkable=True, checked=False) self.toggle_button.setStyleSheet("QToolButton { border: none; }") self.toggle_button.setToolButtonStyle( QtCore.Qt.ToolButtonTextBesideIcon) self.toggle_button.setArrowType(QtCore.Qt.RightArrow) self.toggle_button.pressed.connect(self.on_pressed) self.toggle_animation = QtCore.QParallelAnimationGroup(self) self.content_area = QtWidgets.QScrollArea(maximumHeight=0, minimumHeight=0) self.content_area.setWidgetResizable(True) self.content_area.setSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding) self.content_area.setFrameShape(QtWidgets.QFrame.NoFrame) lay = QtWidgets.QVBoxLayout(self) lay.setSpacing(0) lay.setContentsMargins(0, 0, 0, 0) lay.addWidget(self.toggle_button) lay.addWidget(self.content_area) self.toggle_animation.addAnimation( QtCore.QPropertyAnimation(self, b"minimumHeight")) self.toggle_animation.addAnimation( QtCore.QPropertyAnimation(self, b"maximumHeight")) self.toggle_animation.addAnimation( QtCore.QPropertyAnimation(self.content_area, b"maximumHeight")) self.is_set_up = False
def __init__(self, title="", parent=None): """ Implementation of collapsible boxes: https://stackoverflow.com/a/52617714/11483674 """ super().__init__(parent) self.toggle_button = QtWidgets.QToolButton( text=title, checkable=True, checked=False ) self.toggle_button.setStyleSheet("QToolButton { border: none; }") self.toggle_button.setToolButtonStyle( QtCore.Qt.ToolButtonTextBesideIcon ) self.toggle_button.setArrowType(QtCore.Qt.RightArrow) self.toggle_button.pressed.connect(self.on_pressed) self.toggle_animation = QtCore.QParallelAnimationGroup(self) self.content_area = QtWidgets.QScrollArea( maximumHeight=0, minimumHeight=0 ) self.content_area.setSizePolicy( QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed ) self.content_area.setFrameShape(QtWidgets.QFrame.NoFrame) lay = QtWidgets.QVBoxLayout(self) lay.setSpacing(0) lay.setContentsMargins(0, 0, 0, 0) lay.addWidget(self.toggle_button) lay.addWidget(self.content_area) self.toggle_animation.addAnimation( QtCore.QPropertyAnimation(self, b"minimumHeight") ) self.toggle_animation.addAnimation( QtCore.QPropertyAnimation(self, b"maximumHeight") ) self.toggle_animation.addAnimation( QtCore.QPropertyAnimation(self.content_area, b"maximumHeight") )
def __init__(self, title="", parent=None): super(CollapsibleBox, self).__init__(parent) self.toggle_button = QtWidgets.QToolButton(text=title, checkable=True, checked=True) self.toggle_button.setStyleSheet( "QToolButton { border: none;\nbackground-color: rgb(100,100,100); }" ) self.toggle_button.setSizePolicy( QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Fixed) self.toggle_button.setToolButtonStyle( QtCore.Qt.ToolButtonTextBesideIcon) self.toggle_button.setArrowType(QtCore.Qt.DownArrow) self.toggle_button.pressed.connect(self.on_pressed) self.toggle_animation = QtCore.QParallelAnimationGroup(self) self.content_area = QtWidgets.QScrollArea(maximumHeight=0, minimumHeight=0) self.content_area.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self.content_area.setFrameShape(QtWidgets.QFrame.NoFrame) lay = QtWidgets.QVBoxLayout(self) lay.setSpacing(0) lay.setContentsMargins(0, 0, 0, 0) lay.addWidget(self.toggle_button) lay.addWidget(self.content_area) self.toggle_animation.addAnimation( QtCore.QPropertyAnimation(self, b"minimumHeight")) self.toggle_animation.addAnimation( QtCore.QPropertyAnimation(self, b"maximumHeight")) self.toggle_animation.addAnimation( QtCore.QPropertyAnimation(self.content_area, b"maximumHeight")) self.toggle_animation.start()
def animateAiHand(self, number): if number == 0: self.animMoveWidget(self.ai_left, 0, 175, 300, QEasingCurve.InExpo, self.resetAiLeftHand) elif number == 1: self.animMoveWidget(self.ai_left, 100, 175, 300, QEasingCurve.InExpo, self.resetAiLeftHand2) elif number == 2: self.animMoveWidget(self.ai_right, -100, 175, 300, QEasingCurve.InExpo, self.resetAiRightHand2) elif number == 3: self.animMoveWidget(self.ai_right, 0, 175, 300, QEasingCurve.InExpo, self.resetAiRightHand) elif number == 4: self.anim3 = QtCore.QParallelAnimationGroup() self.anim3.addAnimation( self.animateWidgetMove(self.ai_left, 25, 0, 240, QEasingCurve.InExpo)) self.anim3.addAnimation( self.animateWidgetMove(self.ai_right, -25, 0, 240, QEasingCurve.InExpo)) self.anim3.finished.connect(self.resetDivideAiHand) self.anim3.start()
def __init__(self): """MainWindow constructor""" super().__init__() self.setWindowTitle('Fight Fighter Game Lobby') cx_form = qtw.QWidget() self.setCentralWidget(cx_form) cx_form.setLayout(qtw.QFormLayout()) heading = qtw.QLabel('Fight Fighter!') cx_form.layout().addRow(heading) inputs = { 'Server': qtw.QLineEdit(), 'Name': qtw.QLineEdit(), 'Password': qtw.QLineEdit(echoMode=qtw.QLineEdit.Password), 'Team': qtw.QComboBox(), 'Ready': qtw.QCheckBox('Check when ready') } teams = ('Crimson Shark', 'Shadow Hawks', 'Night Terrors', 'Blue Crew') inputs['Team'].addItems(teams) for label, widget in inputs.items(): cx_form.layout().addRow(label, widget) self.submit = ColorButton('Connect') self.submit.clicked.connect(lambda: qtw.QMessageBox.information( None, 'Connecting', 'Prepare for Battle!')) self.cancel = ColorButton('Cancel') self.cancel.clicked.connect(self.close) cx_form.layout().addRow(self.submit, self.cancel) ######### # Fonts # ######### # Setting a font heading_font = qtg.QFont('Impact', 32, qtg.QFont.Bold) heading_font.setStretch(qtg.QFont.ExtraExpanded) heading.setFont(heading_font) label_font = qtg.QFont() label_font.setFamily('Impact') label_font.setPointSize(14) label_font.setWeight(qtg.QFont.DemiBold) label_font.setStyle(qtg.QFont.StyleItalic) for inp in inputs.values(): cx_form.layout().labelForField(inp).setFont(label_font) # Dealing with miss fonts button_font = qtg.QFont('Totally Nonexistant Font Family XYZ', 15.233) print(f'Font is {button_font.family()}') actual_font = qtg.QFontInfo(button_font).family() print(f'Actual font used is {actual_font}') button_font.setStyleHint(qtg.QFont.Fantasy) button_font.setStyleStrategy(qtg.QFont.PreferAntialias) actual_font = qtg.QFontInfo(button_font) print(f'Actual font used is {actual_font.family()}' f' {actual_font.pointSize()}') self.submit.setFont(button_font) self.cancel.setFont(button_font) #################### # Images and Icons # #################### # Add image logo = qtg.QPixmap('logo.png') heading.setPixmap(logo) if logo.width() > 400: logo = logo.scaledToWidth(400, qtc.Qt.SmoothTransformation) # Create images go_pixmap = qtg.QPixmap(qtc.QSize(32, 32)) stop_pixmap = qtg.QPixmap(qtc.QSize(32, 32)) go_pixmap.fill(qtg.QColor('green')) stop_pixmap.fill(qtg.QColor('red')) # Create icon connect_icon = qtg.QIcon() connect_icon.addPixmap(go_pixmap, qtg.QIcon.Active) connect_icon.addPixmap(stop_pixmap, qtg.QIcon.Disabled) self.submit.setIcon(connect_icon) self.submit.setDisabled(True) inputs['Server'].textChanged.connect( lambda x: self.submit.setDisabled(x == '')) # using resources inputs['Team'].setItemIcon(0, qtg.QIcon(':/teams/crimson_sharks.png')) inputs['Team'].setItemIcon(1, qtg.QIcon(':/teams/shadow_hawks.png')) inputs['Team'].setItemIcon(2, qtg.QIcon(':/teams/night_terrors.png')) inputs['Team'].setItemIcon(3, qtg.QIcon(':/teams/blue_crew.png')) libsans_id = qtg.QFontDatabase.addApplicationFont( ':/fonts/LiberationSans-Regular.ttf') family = qtg.QFontDatabase.applicationFontFamilies(libsans_id)[0] libsans = qtg.QFont(family) inputs['Team'].setFont(libsans) ########## # Colors # ########## app = qtw.QApplication.instance() palette = app.palette() palette.setColor(qtg.QPalette.Button, qtg.QColor('#333')) palette.setColor(qtg.QPalette.ButtonText, qtg.QColor('#3F3')) palette.setColor(qtg.QPalette.Disabled, qtg.QPalette.Button, qtg.QColor('#888')) palette.setColor(qtg.QPalette.Disabled, qtg.QPalette.ButtonText, qtg.QColor('#F88')) self.submit.setPalette(palette) self.cancel.setPalette(palette) dotted_brush = qtg.QBrush(qtg.QColor('white'), qtc.Qt.Dense2Pattern) gradient = qtg.QLinearGradient(0, 0, self.width(), self.height()) gradient.setColorAt(0, qtg.QColor('navy')) gradient.setColorAt(0.5, qtg.QColor('darkred')) gradient.setColorAt(1, qtg.QColor('orange')) gradient_brush = qtg.QBrush(gradient) window_palette = app.palette() window_palette.setBrush(qtg.QPalette.Window, gradient_brush) window_palette.setBrush(qtg.QPalette.Active, qtg.QPalette.WindowText, dotted_brush) self.setPalette(window_palette) ################## # Qt StyleSheets # ################## stylesheet = """ QMainWindow { background-color: black; } QWidget { background-color: transparent; color: #3F3; } QLineEdit, QComboBox, QCheckBox { font-size: 16pt; } """ stylesheet += """ QPushButton { background-color: #333; } QCheckBox::indicator:unchecked { border: 1px solid silver; background-color: darkred; } QCheckBox::indicator:checked { border: 1px solid silver; background-color: #3F3; } """ # Using discrete classes stylesheet += """ .QWidget { background: url(tile.png); } """ self.submit.setObjectName('SubmitButton') stylesheet += """ #SubmitButton:disabled { background-color: #888; color: darkred; } """ for inp in ('Server', 'Name', 'Password'): inp_widget = inputs[inp] inp_widget.setStyleSheet('background-color: black') # self.setStyleSheet(stylesheet) ############# # Animation # ############# self.heading_animation = qtc.QPropertyAnimation( heading, qtc.QByteArray(b'maximumSize')) self.heading_animation.setStartValue(qtc.QSize(10, logo.height())) self.heading_animation.setEndValue(qtc.QSize(500, logo.height())) self.heading_animation.setDuration(2000) self.text_color_animation = qtc.QPropertyAnimation( self.submit, qtc.QByteArray(b'color')) self.text_color_animation.setStartValue(qtg.QColor('#FFF')) self.text_color_animation.setEndValue(qtg.QColor('#888')) self.text_color_animation.setLoopCount(-1) self.text_color_animation.setEasingCurve(qtc.QEasingCurve.InOutQuad) self.text_color_animation.setDuration(2000) self.bg_color_animation = qtc.QPropertyAnimation( self.submit, qtc.QByteArray(b'backgroundColor')) self.bg_color_animation.setStartValue(qtg.QColor('#000')) self.bg_color_animation.setKeyValueAt(0.5, qtg.QColor('darkred')) self.bg_color_animation.setEndValue(qtg.QColor('#000')) self.bg_color_animation.setLoopCount(-1) self.bg_color_animation.setDuration(1500) self.button_animations = qtc.QParallelAnimationGroup() self.button_animations.addAnimation(self.text_color_animation) self.button_animations.addAnimation(self.bg_color_animation) self.all_animations = qtc.QSequentialAnimationGroup() self.all_animations.addAnimation(self.heading_animation) self.all_animations.addAnimation(self.button_animations) self.all_animations.start() self.show()
def __init__(self, parent=None, title='', animationDuration=300): """ References: # Adapted from c++ version http://stackoverflow.com/questions/32476006/how-to-make-an-expandable-collapsable-section-widget-in-qt """ super(Spoiler, self).__init__(parent=parent) self.animationDuration = animationDuration self.toggleAnimation = QtCore.QParallelAnimationGroup() self.contentArea = QtWidgets.QScrollArea() self.headerLine = QtWidgets.QFrame() self.toggleButton = QtWidgets.QToolButton() self.mainLayout = QtWidgets.QGridLayout() toggleButton = self.toggleButton toggleButton.setStyleSheet("QToolButton { border: none; }") toggleButton.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) toggleButton.setArrowType(QtCore.Qt.RightArrow) toggleButton.setText(str(title)) toggleButton.setCheckable(True) toggleButton.setChecked(False) headerLine = self.headerLine headerLine.setFrameShape(QtWidgets.QFrame.HLine) headerLine.setFrameShadow(QtWidgets.QFrame.Sunken) headerLine.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Maximum) self.contentArea.setStyleSheet( "QScrollArea { background-color: white; border: none; }") self.contentArea.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) # start out collapsed self.contentArea.setMaximumHeight(0) self.contentArea.setMinimumHeight(0) # let the entire widget grow and shrink with its content toggleAnimation = self.toggleAnimation toggleAnimation.addAnimation( QtCore.QPropertyAnimation(self, "minimumHeight")) toggleAnimation.addAnimation( QtCore.QPropertyAnimation(self, "maximumHeight")) toggleAnimation.addAnimation( QtCore.QPropertyAnimation(self.contentArea, "maximumHeight")) # don't waste space mainLayout = self.mainLayout mainLayout.setVerticalSpacing(0) mainLayout.setContentsMargins(0, 0, 0, 0) row = 0 mainLayout.addWidget(self.toggleButton, row, 0, 1, 1, QtCore.Qt.AlignLeft) mainLayout.addWidget(self.headerLine, row, 2, 1, 1) row += 1 mainLayout.addWidget(self.contentArea, row, 0, 1, 3) self.setLayout(self.mainLayout) def start_animation(): arrow_type = QtCore.Qt.DownArrow if toggleButton.isChecked( ) else QtCore.Qt.RightArrow direction = QtCore.QAbstractAnimation.Forward if toggleButton.isChecked( ) else QtCore.QAbstractAnimation.Backward toggleButton.setArrowType(arrow_type) self.toggleAnimation.setDirection(direction) self.toggleAnimation.start() self.toggleButton.clicked.connect(start_animation)
def __init__(self, parent=None): self.thread = databaseThread() self.thread.start() self.bgPix = QtGui.QPixmap('img/bg.jpg') self.scene = QtWidgets.QGraphicsScene(0, 0, 835, 470) self.timer = list() self.states = QtCore.QStateMachine() self.group = QtCore.QParallelAnimationGroup() self.items = [] self.text = list() self.names = list() while (len(itemsSignals) != len(names) or len(itemsSignals) == 0 or len(names) == 0): continue self.names = names for i, name in enumerate(self.names): self.kineticPix = QtGui.QPixmap('img/' + name + '.png') # for i in range(len(names)): self.item = Pixmap(self.kineticPix) self.item.pixmap_item.setOffset( self.kineticPix.width() * 0.75 + 82, -self.kineticPix.height() * 0.25) self.item.pixmap_item.setZValue(len(names) - i) self.items.append(self.item) self.scene.addItem(self.item.pixmap_item) self.text.append(self.scene.addText("Loading " + name + '...')) self.text[i].setScale(1.25) self.endPix = QtGui.QPixmap('img/endScene.png') self.endItem = Pixmap(self.endPix) self.endItem.pixmap_item.setOffset(95, 0) self.endItem.pixmap_item.setZValue(1) self.scene.addItem(self.endItem.pixmap_item) self.tiledStates = list() # States. self.rootState = QtCore.QState() for i in range(0, len(names)): self.tiledStates.append(QtCore.QState(self.rootState)) self.centeredState = QtCore.QState(self.rootState) self.endState = QtCore.QState(self.rootState) # Values. for i, item in enumerate(self.items): # Tiled. self.tiledStates[i].assignProperty( item, 'pos', QtCore.QPointF((i % 5) * self.kineticPix.width() * 1.2 - self.kineticPix.width() / 2, (i // 5) * self.kineticPix.height() * 1.2 + self.kineticPix.height() / 2)) for j in range(0, len(self.names)): self.tiledStates[i].assignProperty(self.text[j], 'pos', QtCore.QPointF(-1000, 440)) self.tiledStates[i].assignProperty(self.text[i], 'pos', QtCore.QPointF(10, 440)) # Centered. self.centeredState.assignProperty( item, 'pos', QtCore.QPointF( 312 - (self.kineticPix.width() * len(self.items) * 0.5 * 0.3) - (self.kineticPix.width() * 0.5) + i * self.kineticPix.width() * 0.3, 350 - self.kineticPix.height() * 0.5)) self.centeredState.assignProperty(self.endItem, 'pos', QtCore.QPointF(0, 1000)) self.centeredState.assignProperty(self.text[i], 'pos', QtCore.QPointF(10, 1000)) # End state. self.endState.assignProperty( item, 'pos', QtCore.QPointF(312 - self.kineticPix.width() * 1.25, -1000)) self.endState.assignProperty(self.text[i], 'pos', QtCore.QPointF(10, 1000)) self.endState.assignProperty(self.endItem, 'pos', QtCore.QPointF(0, 145)) # Ui. self.view = View(self.scene) self.view.setWindowTitle("Altium Library Converter") self.view.setViewportUpdateMode( QtWidgets.QGraphicsView.BoundingRectViewportUpdate) self.view.setBackgroundBrush(QtGui.QBrush(self.bgPix)) self.view.setCacheMode(QtWidgets.QGraphicsView.CacheBackground) self.view.setRenderHints(QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) self.view.show()
def __init__(self, parent=None, title='HaHaHaHaHaHa'): super(Spoiler, self).__init__(parent) #if 此处可以跳过不看 self.groupBox = QtWidgets.QGroupBox(self) self.verticalLayout = QtWidgets.QVBoxLayout(self.groupBox) self.pushButton3 = QtWidgets.QPushButton(self.groupBox) self.verticalLayout.addWidget(self.pushButton3) self.pushButton2 = QtWidgets.QPushButton(self.groupBox) self.verticalLayout.addWidget(self.pushButton2) self.label_2 = QtWidgets.QLabel(self.groupBox) self.verticalLayout.addWidget(self.label_2) self.pushButton = QtWidgets.QPushButton(self.groupBox) self.verticalLayout.addWidget(self.pushButton) self.animationDuration = 300 #动画 持续? self.toggleAnimation = QtCore.QParallelAnimationGroup() #动画? self.contentArea = QtWidgets.QScrollArea() #滚动视图? self.headerLine = QtWidgets.QFrame() #框架? self.toggleButton = QtWidgets.QToolButton() #快速访问按钮 self.mainLayout = QtWidgets.QGridLayout() #布局 toggleButton = self.toggleButton toggleButton.setToolButtonStyle( QtCore.Qt.ToolButtonTextBesideIcon) #设置按钮风格 toggleButton.setArrowType(QtCore.Qt.RightArrow) toggleButton.setText(str(title)) toggleButton.setCheckable(True) #属性 可以被选中 toggleButton.setChecked(False) #值 未被选中 # toggleButton = self.toggleButton # toggleButton.setText(str(title)) # toggleButton.setCheckable(True) #可以被选中 # toggleButton.setChecked(False) #不可被选中状态 headerLine = self.headerLine headerLine.setFrameShape(QtWidgets.QFrame.HLine) headerLine.setFrameShadow(QtWidgets.QFrame.Sunken) headerLine.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Maximum) #endif 以下开始为源代码 self.contentArea.setStyleSheet( "QScrollArea { background-color: white; border: none; }") self.contentArea.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) # start out collapsed self.contentArea.setMaximumHeight(0) self.contentArea.setMinimumHeight(0) # let the entire widget grow and shrink with its content toggleAnimation = self.toggleAnimation toggleAnimation.addAnimation( QtCore.QPropertyAnimation(self, b"minimumHeight")) toggleAnimation.addAnimation( QtCore.QPropertyAnimation(self, b"maximumHeight")) toggleAnimation.addAnimation( QtCore.QPropertyAnimation(self.contentArea, b"maximumHeight")) # don't waste space mainLayout = self.mainLayout mainLayout.setVerticalSpacing(0) mainLayout.setContentsMargins(0, 0, 0, 0) row = 0 mainLayout.addWidget(self.toggleButton, row, 0, 1, 1, QtCore.Qt.AlignLeft) mainLayout.addWidget(self.headerLine, row, 2, 1, 1) row += 1 mainLayout.addWidget(self.contentArea, row, 0, 1, 3) self.setLayout(self.mainLayout) def start_animation(checked): arrow_type = QtCore.Qt.DownArrow if checked else QtCore.Qt.RightArrow direction = QtCore.QAbstractAnimation.Forward if checked else QtCore.QAbstractAnimation.Backward toggleButton.setArrowType(arrow_type) self.toggleAnimation.setDirection(direction) self.toggleAnimation.start() self.toggleButton.clicked.connect(start_animation)
# Ui. view = View(scene) view.setWindowTitle("Animated Tiles") view.setViewportUpdateMode(QtGui.QGraphicsView.BoundingRectViewportUpdate) view.setBackgroundBrush(QtGui.QBrush(bgPix)) view.setCacheMode(QtGui.QGraphicsView.CacheBackground) view.setRenderHints( QtGui.QPainter.Antialiasing | QtGui.QPainter.SmoothPixmapTransform) view.show() states = QtCore.QStateMachine() states.addState(rootState) states.setInitialState(rootState) rootState.setInitialState(centeredState) group = QtCore.QParallelAnimationGroup() for i, item in enumerate(items): anim = QtCore.QPropertyAnimation(item, 'pos') anim.setDuration(750 + i * 25) anim.setEasingCurve(QtCore.QEasingCurve.InOutBack) group.addAnimation(anim) trans = rootState.addTransition(ellipseButton.pressed, ellipseState) trans.addAnimation(group) trans = rootState.addTransition(figure8Button.pressed, figure8State) trans.addAnimation(group) trans = rootState.addTransition(randomButton.pressed, randomState) trans.addAnimation(group)
def __init__(self, title='', parent=None, layout=None, animationDuration=100): super().__init__(parent) self.layout_set = False self.animationDuration = animationDuration self.toggleAnimation = QtCore.QParallelAnimationGroup() self.contentArea = QtWidgets.QScrollArea() self.headerLine = QtWidgets.QFrame() self.toggleButton = QtWidgets.QToolButton() self.mainLayout = QtWidgets.QGridLayout() toggleButton = self.toggleButton toggleButton.setStyleSheet("QToolButton { border: none; }") toggleButton.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) toggleButton.setArrowType(QtCore.Qt.RightArrow) toggleButton.setText(title) toggleButton.setCheckable(True) toggleButton.setChecked(False) headerLine = self.headerLine headerLine.setFrameShape(QtWidgets.QFrame.HLine) headerLine.setFrameShadow(QtWidgets.QFrame.Sunken) headerLine.setVisible(False) headerLine.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Maximum) self.contentArea.setStyleSheet( "QScrollArea { background-color: white; border: none; }") self.contentArea.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) # start collapsed by default self.contentArea.setMaximumHeight(0) self.contentArea.setMinimumHeight(0) # let the entire widget grow and shrink with its content toggleAnimation = self.toggleAnimation toggleAnimation.addAnimation( QtCore.QPropertyAnimation(self, b"minimumHeight")) toggleAnimation.addAnimation( QtCore.QPropertyAnimation(self, b"maximumHeight")) toggleAnimation.addAnimation( QtCore.QPropertyAnimation(self.contentArea, b"maximumHeight")) # don't waste space mainLayout = self.mainLayout mainLayout.setVerticalSpacing(0) mainLayout.setContentsMargins(0, 0, 0, 0) row = 0 mainLayout.addWidget(self.toggleButton, row, 0, 1, 1, QtCore.Qt.AlignLeft) mainLayout.addWidget(self.headerLine, row, 2, 1, 1) row = 1 mainLayout.addWidget(self.contentArea, row, 0, 1, 3) self.setLayout(self.mainLayout) def start_animation(checked): arrow_type = QtCore.Qt.DownArrow if checked else QtCore.Qt.RightArrow toggleButton.setArrowType(arrow_type) if toggleButton.isChecked() != checked: toggleButton.setChecked(checked) if not self.layout_set: warnings.warn("No layout set for expanding widget") return direction = QtCore.QAbstractAnimation.Forward if checked else QtCore.QAbstractAnimation.Backward toggleAnimation.setDirection(direction) toggleAnimation.start() self.toggleButton.clicked.connect(start_animation) # make animation accessible as callable attributes self.expand = partial(start_animation, True) self.collapse = partial(start_animation, False) if layout is not None: self.setContentLayout(layout)