PySide flow
-
There's a code that starts an app, then starts a flow that changes the size of the item in the annex every second:
class UsageLine(QFrame): def __init__(self, parent): super().__init__(parent) self.setGeometry(10, 55, 10, 4) self.setStyleSheet('background-color: rgb(17, 125, 187); border-radius: 2px;') self.animation = QPropertyAnimation(self, b"size", EasingCurve=QEasingCurve.OutCubic)
def set(self, percentage): self.animation.setEndValue(QSize(percentage * 3, 4)) self.animation.start()
class GUI(QMainWindow):
# something
self.cpu_usage = UsageLine(cpu_usage_frame)
Thread(target=self.dashboard_controller, daemon=True).start()
self.show()def dashboard_controller(self): while True: if self.currentSpace.currentIndex() == 0: self.cpu_usage.set(50) sleep(1)
Function
set
Called, but no animation.https://stackoverflow.com/questions/45175427/pyqt5-run-function-after-displaying-window There's something like that, but I don't know how to use it.
Thank you.
-
♪ Qt sufficient of its means, which provide an independent flow management tool for the platform.
But for your fragment that you showed, no additional flows are needed.
You've got enough to use.QTimer
♪Class
QTimer
Provides repetitive and one-time timers.
More. https://doc.qt.io/qt-5/qtimer.htmlThis is one possible solution:
import sys from PyQt5.Qt import *
class UsageLine(QFrame):
def init(self, parent=None):
super().init(parent)self.setGeometry(10, 55, 10, 4)
self.setGeometry(10, 55, 0, 4) self.setStyleSheet('background-color: rgb(17, 125, 187); border-radius: 2px;') self.animation = QPropertyAnimation( self, b"size", easingCurve=QEasingCurve.OutCubic ) self.animation.setDuration(1000) def set(self, percentage): self.animation.setEndValue(QSize(percentage * 3, 4)) self.animation.start()
class GUI(QMainWindow):
def init(self):
super().init()
self.centralWidget = QWidget()
self.setCentralWidget(self.centralWidget)self.percentage = 0 # something self.cpu_usage = UsageLine(self.centralWidget) #(cpu_usage_frame)
Thread(target=self.dashboard_controller, daemon=True).start()
self.timer = QTimer() self.timer.timeout.connect(self.dashboard_controller) QTimer.singleShot(10, self.timer_start) def timer_start(self): self.timer.start(1000) def dashboard_controller(self):
while True:
??? if self.currentSpace.currentIndex() == 0:
self.percentage += 10 self.cpu_usage.set(self.percentage) if self.percentage >= 100: self.timer.stop()
sleep(1)
if name == "main":
app = QApplication(sys.argv)
window = GUI()
window.resize(320, 150)
window.show()
sys.exit(app.exec_())