Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
474 views
in Technique[技术] by (71.8m points)

python - Is there a PyQT equivalent to wx.FutureCall (calling a function after window is initialized and drawn)?

I am trying to delay setting variables after my main window is opened. I have tried showEvent() but that doesn't work. I know in wxPython there is wx.FutureCall method to use in this type of situation:

class MyFrame(wx.Frame): 

 def __init__(..frame init parms.., ..your init parms..): 
   wx.Frame.__init__(..frame init parms..) 
   self.Show() 
   wx.FutureCall(500,self.OnLoad)   #1/2 seconds from now to call OnLoad() 

 def OnLoad(self, ..your init parms..): 
   ..your init code.. 
   self.Refresh() 

My question is: how can I delay doing some actions after my PyQT main window does its initialization and is finally shown? How can I do this:

class MyWindow(QtGui.QMainWindow):
  def __init__(self,parent=None):

    QtGui.QWidget.__init__(self,parent)

    ... init stuff here...

    self.FutureCall(500,self.OnLoad)

  def OnLoad(self,event):
    ... my stuff here...

Thanks in advance! -Paul

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I don't know why showEvent is not working for you. For me it is working as expected. It is fired after the window is shown.

For the delayed call, you can use QTimer.singleShot:

class MyWindow(QtGui.QMainWindow):
  def __init__(self, parent=None):

    QtGui.QWidget.__init__(self, parent)

    ... init stuff here...

    QtCore.QTimer.singleShot(500, self.OnLoad)

  def OnLoad(self):
    ... my stuff here...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...