Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

qt

qt4

pyqt

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

like image 910
Paul Avatar asked May 20 '12 21:05

Paul


People also ask

Is PyQt good for GUI?

PyQt is a Python binding for Qt, which is a set of C++ libraries and development tools that include platform-independent abstractions for Graphical User Interfaces (GUI), as well as networking, threads, regular expressions, SQL databases, SVG, OpenGL, XML, and many other powerful features.

What is QWidget in PyQt5?

The QWidget widget is the base class of all user interface objects in PyQt5. We provide the default constructor for QWidget . The default constructor has no parent. A widget with no parent is called a window.

What is PyQt5 Qtgui?

PyQt5 - Introduction PyQt is a GUI widgets toolkit. It is a Python interface for Qt, one of the most powerful, and popular cross-platform GUI library. PyQt was developed by RiverBank Computing Ltd. The latest version of PyQt can be downloaded from its official website − riverbankcomputing.com.

How do I create a window in PyQt5?

We set the window size using the setGeometry(left,top,width,height) method. The window title is set using setWindowTitle(title). Finally show() is called to display the window.


1 Answers

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...
like image 60
Avaris Avatar answered Oct 13 '22 05:10

Avaris