Results 1 to 2 of 2

Thread: Qt Antialiasing with QPainter versus QStyleSheets

  1. #1
    Join Date
    Dec 2012
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question Qt Antialiasing with QPainter versus QStyleSheets

    Here are two QWidget painted black. The painting on left QWidget was performed using QPainter(overriding ::paintEvent(...)). The right widget was "painted" using QStyleSheet.



    This work was done in PyQt4 (Python: 2.7.11+/Qt: 4.8.7/PyQt4: 4.11.4). But you I have achieved the same result using PyQt5 and C++ Qt4/Qt5.
    The code I used to paint the left QWidget is
    Qt Code:
    1. def paintEvent( self, pEvent ) :
    2. painter = QPainter( self )
    3. painter.setRenderHints( QPainter.HighQualityAntialiasing )
    4.  
    5. painter.setPen( Qt.black )
    6. painter.setBrush( Qt.black )
    7.  
    8. painter.drawRoundedRect( self.rect(), 10.0, 10.0 )
    9.  
    10. painter.end()
    11.  
    12. pEvent.accept()
    To copy to clipboard, switch view to plain text mode 

    The stylesheet used on the right widget is

    Qt Code:
    1. setStyleSheet( "border-radius: 10px; border: 1px solid black; background: black;" )
    To copy to clipboard, switch view to plain text mode 

    Why is there a difference between the two, especially the rounded part drawn by QStyleSheet far more smoother than the one done by QPainter despite using QPainter.HighQualityAntialiasing render hint? You could use just QPainter.Antialiasing or QPainter.TextAntialiasing and still the situation does not improve.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt Antialiasing with QPainter versus QStyleSheets

    Maybe the left rectangle is cut off?
    Have you tried using a rect that is the widget's rect but with 1px offset from each side?

    Cheers,
    _

Similar Threads

  1. QPainter Antialiasing for QImage
    By mupilz in forum Qt Programming
    Replies: 1
    Last Post: 14th February 2012, 18:51
  2. Replies: 0
    Last Post: 25th May 2011, 20:01
  3. Replies: 5
    Last Post: 7th September 2009, 21:57
  4. What different between version 4.3.1 versus 4.3.2?
    By Teerayoot in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2007, 15:30
  5. QTableView versus QTableWidget
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2006, 20:51

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.