<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Le 14/03/11 03:42, jp984 a écrit :
    <blockquote cite="mid:31140528.post@talk.nabble.com" type="cite">
      <pre wrap="">
Hello there.

Im learning pyqt using  "rapid gui programing with pyqt" book, Im making a
change on the chapter's 11 exercise solution given by the book. I want the
widget to change the focus on each rectangle automatically every half of a
second. So i replace the mouse and key event handlers for a method to do the
work.

It looks .update() method doest work properly,the widget shows the widget at
the initial state and then it isn't updated  can any of you guys give me a
hint:

The move method does change the focus on each rectangle (x,y)the grid.

this is the code:


class CountersWidget(QWidget):

    def __init__(self, parent=None):
        super(CountersWidget, self).__init__(parent)
        self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding,
                                       QSizePolicy.Expanding))
        self.grid = [[BLANK] * 3 for i in range(3)]
        self.selected = [0, 0]
        self.setMinimumSize(self.minimumSizeHint())


    def sizeHint(self):
        return QSize(200, 200)


    def minimumSizeHint(self):
        return QSize(100, 100)

    def move(self):
         if self.selected[0] == 2:
                self.selected=([0,self.selected[1]+1] if not
self.selected[1]==2
                                else [0,0])
         else:
                self.selected = [self.selected[0]+1, self.selected[1]]
         x, y = self.selected
         cell= self.grid[x][y]
         print (self.selected)
         self.grid[x][y]=cell
         self.update()
         self.emit(SIGNAL("movido"))

    def delay(self):
        time.sleep(0.5)
        self.emit(SIGNAL("delay"))


    def paintEvent(self, event=None):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        xOffset = self.width() / 3
        yOffset = self.height() / 3
        for x in range(3):
            for y in range(3):
                cell = self.grid[x][y]
                rect = (QRectF(x * xOffset, y * yOffset,
                        xOffset, yOffset).adjusted(0.5, 0.5, -0.5, -0.5))
                color = None
                            
                if [x, y] == self.selected:
                    painter.setPen(QPen(Qt.blue, 3))
                else:
                    painter.setPen(Qt.black)
                painter.drawRect(rect)
                QTimer.singleShot(0,self.delay)

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    form = CountersWidget()
    form.setWindowTitle("Counters")
    form.show()
    app.exec_()


</pre>
    </blockquote>
    Use QtCore.QCoreApplication.processEvents() instead of update()<br>
    <br>
    <div class="moz-signature">-- <br>
      Vincent V.V.<br>
      <a href="https://launchpad.net/oqapy">Oqapy</a></div>
  </body>
</html>