gpt4 book ai didi

python - 如果不卡住主线程,我怎么能等

转载 作者:太空宇宙 更新时间:2023-11-04 11:12:05 25 4
gpt4 key购买 nike

我想做一个从侧面滚出来的形状,但它只是传送

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()

我启动它,我的程序只是卡住了几秒钟,然后一切都传送了起来,但我希望它更流畅

最佳答案

我知道你希望小部件平滑移动,在这种情况下,解决方案是使用 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)

关于python - 如果不卡住主线程,我怎么能等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57957712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com