PDA

View Full Version : Interacting with qt while other qt functions are running



di_zou
5th January 2010, 16:36
I have a QGraphicsScene and QGraphicsView. When I click a button, QGraphicsItems will movearound in the scene. When this happens, I can't do anything else in my Qt app. How do I make it so that I can do other things while my QGraphicsItems are being updated?

Also, I have a stop button. I want to be able to click the stop button to stop the QGraphicsItems from moving. How do I do that?

wysota
5th January 2010, 17:04
Please show us your code. You are probably blocking the event loop. You should be using the animation framework.

di_zou
5th January 2010, 17:22
class MainWidget(QWidget):
def __init__(self):
QWidget.__init__(self)

self.display = DisplayScene(self)
self.view = DisplayView(self.display)
self.view.show()

self.playButton = QPushButton("Play")
self.stepLineEdit = QLineEdit()
def Update(self):
if self.display.nodeExist():
if int(self.stepLineEdit.text()) < self.display.getMovementSteps():
#if self.display.nodeExist():
value = self.stepSizeLineEdit.text()
self.stepSizeSlider.setValue(int(value))
self.stepSize = value
self.display.updateScene(int(self.stepLineEdit.tex t()))
def Play(self):
if self.display.nodeExist():
i = int(self.stepLineEdit.text())
self.display.ViewNodeMovement()
totalMovementSteps = self.display.getMovementSteps()
i = i + int(self.stepSize)
#print totalMovementSteps
while i < totalMovementSteps:
self.stepLineEdit.setText(str(i))

i = i + int(math.ceil(totalMovementSteps / 1000.0))
self.Update()
graphViews = self.display.views()
graphViews [ 0 ].repaint()
self.stepLineEdit.repaint()

class DisplayScene(QGraphicsScene):
def updateScene(self, index):
self.currentTimeStep += index - self.currentStep

self.currentStep = index

graphViews = self.views()
sceneItems = self.items()
for item in sceneItems:
self.removeItem(item)
self.drawScene(sceneItems, graphViews)
def drawScene(self, sceneItems, graphViews):
nodePlatformList = [ ]
for item in sceneItems:

item.setGraphView(graphViews[0])
#stuff#
self.addItem(item)

I have a good bit of code, so i cut out a lot of it. If something is not clear, just ask. Basically what happens is I have a play button, and when I click it it cycles through a while loop to update the display scene. So I guess what I want to do is to have some way to stop the while loop.

wysota
5th January 2010, 18:05
The while loop has to go. Or at least run QApplication::processEvents() in each iteration.

Tanuki-no Torigava
8th January 2010, 01:30
May be you should stop using while loops and use asynchronous signal/slot approach?

di_zou
8th January 2010, 18:03
May be you should stop using while loops and use asynchronous signal/slot approach?

Where can I get info to implement an asynchronous signal?

I got it working now with a QApplication.proccessEvents(). I can click the stop button and it will stop the while loop.