[PyQt] Qpainter doesn't draw anything under Windows. Linux is fine.

Василий Чинарёв vasa.chi at gmail.com
Thu Mar 11 11:15:01 GMT 2010


I want to update a pixmap on single click, so I tried this:

import sys
from PyQt4 import QtGui,QtCore

class myLabel(QtGui.QLabel):
    def __init__(self,*args,**kwargs):
        QtGui.QLabel.__init__(self,*args,**kwargs)

        self.painter = QtGui.QPainter()

    def mousePressEvent(self, ev):
        QtGui.QLabel.mousePressEvent(self,ev)
        pm = self.pixmap()
        self.painter.begin(pm)
        self.painter.setPen(QtGui.QPen(QtCore.Qt.red, 120))

        self.painter.drawPoint(ev.pos())
        self.painter.end()
        self.setPixmap(pm)
        print ev.pos()


if __name__=='__main__':
    app = QtGui.QApplication(sys.argv)

    mw = QtGui.QWidget()
    model_pm = QtGui.QPixmap(300,300)
    model_l = myLabel()
    model_res_pm = QtGui.QPixmap(300,300)
    model_res_l = myLabel()
    draw_pm = QtGui.QPixmap(300,300)
    draw_l = myLabel()

    draw_res_pm = QtGui.QPixmap(300,300)
    draw_res_l = myLabel()
    map(lambda pm: pm.fill(),(model_pm,model_res_pm,draw_pm,draw_res_pm))

    model_l.setPixmap(model_pm)
    model_res_l.setPixmap(model_res_pm)

    draw_l.setPixmap(draw_pm)
    draw_res_l.setPixmap(draw_res_pm)
    layout = QtGui.QGridLayout()
    layout.addWidget(model_l,0,0,1,1)
    layout.addWidget(model_res_l,1,0,1,1)
    layout.addWidget(draw_l,0,1,1,1)

    layout.addWidget(draw_res_l,1,1,1,1)
    mw.setLayout(layout)
    mw.show()
    mw.setFixedSize(mw.geometry().size())
    sys.exit(app.exec_())


On Linux a big red square shows on click (wich is good). But under Windows
pixmaps remain white (checked under Win7 and XP). Looks like a bug to me...

Code on pastebin: http://pastebin.com/BKtNQ8rb

PyQt-4.7 and Python 2.6.4 on both Linux and Windows.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100311/674c8ce9/attachment.html>


More information about the PyQt mailing list