egaudrain
9th November 2011, 14:57
Hi,
I'm using PyQt4 (4.8.4, based on Qt 4.7.2). I want to display pixmaps on the screen every time the user presses a key. So far so good.
But I also want to scale and rotate the images. Then bad things happen. I use the GraphicsScene framework and the setRotation item method to rotate the pixmap. This much works except that I don't seem to be able get any smoothing to work.
Here's my code:
class MainWindow(QWidget):
def __init__(self):
QMainWindow.__init__(self, None) #, Qt.FramelessWindowHint)
self.setWindowState(Qt.WindowFullScreen)
self.vL = QVBoxLayout()
self.setLayout(self.vL)
self.scene = QGraphicsScene()
self.view = QGraphicsView(self)
#~ self.view.setRenderHint(QPainter.SmoothPixmapTrans form, False)
self.view.setScene(self.scene)
self.view.setHorizontalScrollBarPolicy(Qt.ScrollBa rAlwaysOff)
self.view.setVerticalScrollBarPolicy(Qt.ScrollBarA lwaysOff)
self.vL.addWidget(self.view)
self.view.setRenderHints(QPainter.SmoothPixmapTran sform | QPainter.Antialiasing)
self.view.setSceneRect(0, 0, self.width(), self.height())
self.img_list = glob('img/*.jpg')
self.img_list.extend(glob('img/*.png'))
def keyPressEvent(self, event):
event.accept()
self.disp_image(self.img_list[random.choice(range(len(self.img_list)))])
def disp_image(self, file, position=None):
pxmap = QPixmap(file)
i = self.scene.addPixmap(pxmap)
i.setTransformOriginPoint(pxmap.width()/2., pxmap.height()/2.)
i.setRotation(10)
i.setPos((.8*random.random()+.1)*self.width()-pxmap.width()/2., (.8*random.random()+.1)*self.height()-pxmap.height()/2.)
self.view.show()
Whatever I do, the QPainter.SmoothPixmapTransform seems to be ineffective (see the attachements: one is Tux rotated using Qt, the next is Tux rotated using XnView).
I've tried many many things: using an OpenGL viewport instead of the default raster one; declaring the hints before setting the scene; setting the hints after each item is added to the scene; even tried a method propose elsewhere where the view is retrieved from the item itself; also view.show() doesn't seem to be required or doing anything.
I've spent the last 2 days googling this but couldn't find a clue. Someone seems to have had the same problem in 2007 but got no response...
Any clues?
Ah, I've tried that on WinXP only by the way.
Thanks a lot for any hint!
-Etienne
I'm using PyQt4 (4.8.4, based on Qt 4.7.2). I want to display pixmaps on the screen every time the user presses a key. So far so good.
But I also want to scale and rotate the images. Then bad things happen. I use the GraphicsScene framework and the setRotation item method to rotate the pixmap. This much works except that I don't seem to be able get any smoothing to work.
Here's my code:
class MainWindow(QWidget):
def __init__(self):
QMainWindow.__init__(self, None) #, Qt.FramelessWindowHint)
self.setWindowState(Qt.WindowFullScreen)
self.vL = QVBoxLayout()
self.setLayout(self.vL)
self.scene = QGraphicsScene()
self.view = QGraphicsView(self)
#~ self.view.setRenderHint(QPainter.SmoothPixmapTrans form, False)
self.view.setScene(self.scene)
self.view.setHorizontalScrollBarPolicy(Qt.ScrollBa rAlwaysOff)
self.view.setVerticalScrollBarPolicy(Qt.ScrollBarA lwaysOff)
self.vL.addWidget(self.view)
self.view.setRenderHints(QPainter.SmoothPixmapTran sform | QPainter.Antialiasing)
self.view.setSceneRect(0, 0, self.width(), self.height())
self.img_list = glob('img/*.jpg')
self.img_list.extend(glob('img/*.png'))
def keyPressEvent(self, event):
event.accept()
self.disp_image(self.img_list[random.choice(range(len(self.img_list)))])
def disp_image(self, file, position=None):
pxmap = QPixmap(file)
i = self.scene.addPixmap(pxmap)
i.setTransformOriginPoint(pxmap.width()/2., pxmap.height()/2.)
i.setRotation(10)
i.setPos((.8*random.random()+.1)*self.width()-pxmap.width()/2., (.8*random.random()+.1)*self.height()-pxmap.height()/2.)
self.view.show()
Whatever I do, the QPainter.SmoothPixmapTransform seems to be ineffective (see the attachements: one is Tux rotated using Qt, the next is Tux rotated using XnView).
I've tried many many things: using an OpenGL viewport instead of the default raster one; declaring the hints before setting the scene; setting the hints after each item is added to the scene; even tried a method propose elsewhere where the view is retrieved from the item itself; also view.show() doesn't seem to be required or doing anything.
I've spent the last 2 days googling this but couldn't find a clue. Someone seems to have had the same problem in 2007 but got no response...
Any clues?
Ah, I've tried that on WinXP only by the way.
Thanks a lot for any hint!
-Etienne