[PyQt] Pyqt, repainting on a customize widget.

jp984 jp984 at costarricense.cr
Sat Mar 26 18:41:00 GMT 2011


this is what i get when i try:
QtCore.Qapplication.ProcessEvents()
global name 'QtCore' is not defined


jp984 wrote:
> 
> 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_()
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Pyqt%2C-repainting-on-a-customize-widget.-tp31140528p31246967.html
Sent from the PyQt mailing list archive at Nabble.com.



More information about the PyQt mailing list