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
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()
def paintEvent( self, pEvent ) :
painter = QPainter( self )
painter.setRenderHints( QPainter.HighQualityAntialiasing )
painter.setPen( Qt.black )
painter.setBrush( Qt.black )
painter.drawRoundedRect( self.rect(), 10.0, 10.0 )
painter.end()
pEvent.accept()
To copy to clipboard, switch view to plain text mode
The stylesheet used on the right widget is
setStyleSheet( "border-radius: 10px; border: 1px solid black; background: black;" )
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.
Bookmarks