python - QDialog.show() method has a delayed reaction -


i have problem can't quite figure out time. have main window application , qdialog should pop out after clicking 1 of buttons, show() method on qdialog seems waiting funcion connected "clicked()" signal end! want dialog show right after calling qdialog.show() method, not after other code instructions in function...

of course in code going replace sleep(5) part more complicated code, pictures problem , code put there irrelevant issue, think (database connections , updates) being more specific:

# -*- coding: utf-8 -*- import sys  import pyqt4  pyqt4 import qtcore, qtgui twython import twython, twythonerror project import ui_mainwindow time import sleep import psycopg2, globalvals, updater import updating, noconnection  class upwindow(qtgui.qdialog):     def __init__(self, parent=none):         qtgui.qdialog.__init__(self, parent, qtcore.qt.windowstaysontophint)         self.ui = updating.ui_updating()         self.ui.setupui(self)  class noconnection(qtgui.qdialog):     def __init__(self, parent=none):         qtgui.qdialog.__init__(self, parent, qtcore.qt.windowstaysontophint)         self.ui = noconnection.ui_noconnection()         self.ui.setupui(self)          qtcore.qobject.connect(self.ui.noconnectionclose, qtcore.signal("clicked()"), self.close)  class mycounter(qtgui.qwidget):     def __init__(self, parent=none):         qtgui.qwidget.__init__(self, parent)         self.ui = ui_mainwindow()         self.ui.setupui(self)         self.noconn = noconnection(self)         self.upwin = upwindow(self)          qtcore.qobject.connect(self.ui.refreshbutton,qtcore.signal("clicked()"), self.refresh)         qtcore.qobject.connect(self.ui.managebutton,qtcore.signal("clicked()"), self.manage)      def refresh(self):         self.upwin.show()         self.upwin.show         self.upwin.setvisible(true)         self.setenabled(false)         self.upwin.setenabled(true)         #thats issue - sleep instruction being held         #before showing of upwin qdialog         sleep(5)      def manage(self):         print 'ok'    if __name__ == "__main__":     app = qtgui.qapplication(sys.argv)     myapp = mycounter()     myapp.upcontent()     myapp.show()     sys.exit(app.exec_()) 

think of qt program cooperative-multitasking system. graphics , events in general handled main loop. don't want stay long in slot, because library won't process signals (say button clicks, repaints, other stuff) in mean time.

if want heavy processing, or needs wait resources while rest of program chugging along, use qthread.

another option force event processing qapp.processevents() (you can find qapp in qtgui), before sleep(5) (or whatever code you're going put in place of it).

edit: now, keep in mind forcing event processing show qdialog you're trying popup. can't (remember, no event processing) without calling again qapp.processevents() or returning slot.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -