pyQt window is doesn't update until I change window
I have a program that load a file from hard drive with instruction to
paint several squares of 50x50 points. I also have to comboBox which
should have an effect on the presented squares. Basically, the two
comboBox give the folder and the file name.
Every time I call the comboBox, I can tell that I call the paint event and
the instruction used to paint the tiles are updated based upon the
selection. However, the displayed squares aren't updated until I switch to
another window and then turn back to the original window.
Here is how my paintEvent look
def paintEvent(self,event):
self.updateButtons()
self.updateNameCombo()
qp = QtGui.QPainter()
qp.begin(self)
self.paintTiles(qp)
qp.end()
return
updateButton is used to place the PushButton and ComboBox at the right
side of the screen.UpdateNameComobois used to update one of the comboBoxes
andpainTiles`` is used to paint the squares on the screen.
def paintTiles(self,qp):
self.loadTileSet()
width= self.frameSize().width()
height = self.frameSize().height()
self.endX = width - 120
self.endY = width - 25
x = self.startX
y = self.startY
i = self.startI
while i < len(self.tiles):
self.handleTile(qp,x,y,self.tiles[i])
i += 1
x += 60
if x >= self.endX - 60:
x = self.startX
y += 60
if y >= self.endY - 60:
break
return
loadTileSet is used to read the tile data from the hard drive. and
handleTile is used to paint a single square.
def handleTile(self,qp,x,y,tile):
pen = QtGui.QPen(QtCore.Qt.blue, 1, QtCore.Qt.DotLine)
for line in tile:
r,g,b,a = tile[line]
clr = QtGui.QColor(r,g,b,a)
pen.setColor(clr)
qp.setPen(pen)
pX = x + line[0]
pY = y + line[1]
qp.drawPoint(pX,pY)
So, what hold back the drawing of the tiles?
No comments:
Post a Comment