Results 1 to 3 of 3

Thread: How to apply QPainter::SmoothPixmapTransform to QGracphicsView?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to apply QPainter::SmoothPixmapTransform to QGracphicsView?

    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:

    Qt Code:
    1. class MainWindow(QWidget):
    2. def __init__(self):
    3. QMainWindow.__init__(self, None) #, Qt.FramelessWindowHint)
    4.  
    5. self.setWindowState(Qt.WindowFullScreen)
    6.  
    7. self.vL = QVBoxLayout()
    8. self.setLayout(self.vL)
    9.  
    10. self.scene = QGraphicsScene()
    11. self.view = QGraphicsView(self)
    12.  
    13. #~ self.view.setRenderHint(QPainter.SmoothPixmapTransform, False)
    14. self.view.setScene(self.scene)
    15.  
    16. self.view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
    17. self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
    18. self.vL.addWidget(self.view)
    19.  
    20. self.view.setRenderHints(QPainter.SmoothPixmapTransform | QPainter.Antialiasing)
    21. self.view.setSceneRect(0, 0, self.width(), self.height())
    22.  
    23. self.img_list = glob('img/*.jpg')
    24. self.img_list.extend(glob('img/*.png'))
    25.  
    26.  
    27. def keyPressEvent(self, event):
    28. event.accept()
    29. self.disp_image(self.img_list[random.choice(range(len(self.img_list)))])
    30.  
    31. def disp_image(self, file, position=None):
    32.  
    33. pxmap = QPixmap(file)
    34. i = self.scene.addPixmap(pxmap)
    35. i.setTransformOriginPoint(pxmap.width()/2., pxmap.height()/2.)
    36. i.setRotation(10)
    37. i.setPos((.8*random.random()+.1)*self.width()-pxmap.width()/2., (.8*random.random()+.1)*self.height()-pxmap.height()/2.)
    38.  
    39. self.view.show()
    To copy to clipboard, switch view to plain text mode 

    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
    Attached Images Attached Images

Similar Threads

  1. How to apply font to QString
    By coolkaps in forum Newbie
    Replies: 1
    Last Post: 9th May 2010, 23:27
  2. QPainter(&QPrinter) & QPainter(&QImage) communication
    By gufeatza in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2010, 07:25
  3. Replies: 5
    Last Post: 7th September 2009, 20:57
  4. Where to apply transform? iterm or QPainter?
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2009, 08:40
  5. Replies: 3
    Last Post: 30th April 2006, 19:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.