python - Wait for a clicked() event in while loop in Qt -


how can wait, @ each iteration, within loop, user press given qpushbutton?

for in range(10):           while (the button has not been pressed):             #do nothing         #do 

the main problem cannot catch clicked() event in while loop.

edit:

finally ended with:

 in range(10):         self.hasbeenprocessed = false          # 1 function can modify boolean         # , function connected button         while (self.hasbeenprocessed not true):                 qtcore.qcoreapplication.processevents() 

so, share slight skepticism whether should want doing described. also, share better if show bit more code describe context.

having said this, code below stab @ seem describing. note no means meant production-ready code, more crude example illustrate principle.

what happens call 1 function on press of button1 , keep event loop spinning inside while loop calling qcoreapplication.processevents() means gui still accept e.g. mouse events. now, should not typically do. there are, however, situations can needed, e.g. if have non-modal qprogressdialog , want keep gui updating while dialog counter increases (see e.g. http://doc.qt.io/qt-4.8/qprogressdialog.html#value-prop)

then second part modify global variable in second function when press button 2 , while loop exit.

let me know if helps

import sys pyqt4.qtcore import * pyqt4.qtgui import *  btn2pushed = false  def window():    app = qapplication(sys.argv)    win = qdialog()    b1 = qpushbutton(win)    b1.settext("button1")    b1.move(50,20)    b1.clicked.connect(b1_clicked)     b2 = qpushbutton(win)    b2.settext("button2")    b2.move(50,50)    qobject.connect(b2,signal("clicked()"),b2_clicked)     win.setgeometry(100,100,200,100)    win.setwindowtitle("pyqt")    win.show()    sys.exit(app.exec_())  def b1_clicked():    print "button 1 clicked"    = 0    while ( btn2pushed != true ):        # not doing                                                                                                                                                                                                           if ( % 100000 == 0 ):            print "waiting user push button 2"        qcoreapplication.processevents()        += 1;     print "button 2 has been pushed"   def b2_clicked():     global btn2pushed     btn2pushed = true  if __name__ == '__main__':    window() 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -