My problem is I want to keep rotating the scene if the checkbox is checked, and stop this rotation immediately once it is unchecked. However, "keep rotating" means an infinite loop...
So after entering the loop, the program gets kind of freezed and no longer react to my "uncheck" signal. Is there a way to interrupt this loop? The following is skeleton of related code. Thanks!
class Draw(QGLWidget):
def __init__(...):
...
self.rotate=0
self.auto=False
def paintGL(self):
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glRotatef(self.rotate,0.0,0.0,1.0)
draw stuff...
glFlush()
def autoRotate(self,auto): # auto is an integer and used here as true/false
self.auto=auto
while self.auto:
self.rotate+=0.5
if self.rotate>360:
self.rotate-=360
self.updateGL()
if auto==False:
break
class SpiralWidgetDemo(QtGui.QMainWindow):
def __init__(self):
...
auto=QtGui.QCheckBox("Auto")
self.connect(auto,QtCore.SIGNAL("stateChanged(int)"),widget.autoRotate)