本文介紹了我怎么能等待而不凍結主線程的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想制作一個從側面滾出的表格,但它只是傳送
I want to make a form rolling out from side, but it just teleports
class SubWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.ui = loadUi("SubWindow.ui", self)
butt = QPushButton()
self.UploadButton.clicked.connect(self.UploadButtonClicked)
def UploadButtonClicked(self):
#self.ui.hide()
for x in range(25):
self.LoginText.move(self.LoginText.x(), self.LoginText.y()-10)
self.UploadButton.move(self.UploadButton.x(), self.UploadButton.y()-10)
self.PassText.move(self.PassText.x(), self.PassText.y()-10)
#window.Show()
def Show(self):
self.ui.show()
def Hide(self):
self.ui.hide()
我啟動它,我的程序只是凍結了幾秒鐘,然后一切都傳送了,但我希望它更流暢
I launch this and my program just freeze for few seconds and then everything teleports up, but I want it to be smoother
推薦答案
我了解到您希望小部件平滑移動,這種情況下的解決方案是使用 QPropertyAnimation:
I understand that you want the widget to move smoothly, in that case the solution is to use QPropertyAnimation:
def UploadButtonClicked(self):
animation_group = QParallelAnimationGroup(self)
for w in (self.LoginText, self.UploadButton, self.PassText):
start_pos = w.pos()
end_pos = w.pos() + QPoint(0, -10)
animation = QPropertyAnimation(
self,
propertyName=b"pos",
targetObject=w,
startValue=start_pos,
endValue=end_pos,
duration=1000,
)
animation_group.addAnimation(animation)
animation_group.start(QParallelAnimationGroup.DeleteWhenStopped)
這篇關于我怎么能等待而不凍結主線程的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!