| Hi, I'm seeing a strange issue with either QPixmap or QImage loading from a data string. In pyqt 4.4.4, the following attached example code produces an image - it looks like noise as expected. But with pyqt 4.5.1, it appears completely blank. I expect to see the noise-like image. Am I doing something wrong, or has something changed with regards to this in 4.5? I'm running on Mac OS X 10.5.7 and python 2.5.4 using pyqt installed from Macports. Note: I modified my local portfile to install pyqt 4.5.1 because Macports is currently at version 4.4.4. |
''' Created on Jun 25, 2009 @author: schimaf '''
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class PixmapTestFrameQt(QMainWindow):
'''
Pixmap test main window
'''
def __init__(self, parent=None, title='Pixmap test', width=512, height=512):
super(PixmapTestFrameQt, self).__init__(parent)
print "init pixmap_test_frame"
self.parent = parent
self.sizex = width
self.sizey = height
self.setWindowTitle(title)
self.image_string = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
self.scene = QGraphicsScene(self)
self.scene.setSceneRect(0, 0, self.sizex, self.sizey)
self.view = QGraphicsView()
self.view.setRenderHint(QPainter.Antialiasing)
self.view.setScene(self.scene)
self.setCentralWidget(self.view)
self.menubar = self.menuBar()
self.fileMenu = self.menubar.addMenu("File")
fileQuitAction = QAction("Quit", self.fileMenu)
self.connect(fileQuitAction, SIGNAL("triggered()"), self.onQuit)
thetext = "Window size [%4i, %4i]" % (self.sizex, self.sizey)
self.statusBar().showMessage(thetext)
self.makePixmap()
def makePixmap(self):
myimage = QImage(self.image_string, self.sizex, self.sizey, QImage.Format_Indexed8)
myimage.setColorTable(self.makeColorTable())
pm = QPixmap.fromImage(myimage)
if pm is None:
print "pm is none!"
else:
print "pm", pm.width(), pm.height()
pmi = self.scene.addPixmap(pm)
pmi.setZValue(1)
def makeColorTable(self):
'''Create 256 shades of grey for a color lookup table'''
colorimage = QImage(self.sizex, self.sizey, QImage.Format_Indexed8)
for i in range(256):
colorimage.setColor( i, qRgb(255-i, 255-i, 255-i) )
colortable = colorimage.colorTable()
return colortable
def onQuit(self):
self.Close()
if __name__ == '__main__':
app = QApplication(sys.argv)
win = PixmapTestFrameQt()
win.show()
app.exec_()
Cheers! Frank |
_______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
