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.
http://i.stack.imgur.com/gSrJv.jpg
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
Code:
def paintEvent( self, pEvent ) :
painter.
setRenderHints( QPainter.
HighQualityAntialiasing )
painter.setPen( Qt.black )
painter.setBrush( Qt.black )
painter.drawRoundedRect( self.rect(), 10.0, 10.0 )
painter.end()
pEvent.accept()
The stylesheet used on the right widget is
Code:
setStyleSheet( "border-radius: 10px; border: 1px solid black; background: black;" )
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.
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,
_