How to smooth a gradient (at the corners) on a QPushButton? I have this code:

ui->pushButton->setStyleSheet( "QPushButton {" "background-color: lightGray;" "border-style: solid;" "border-width: 5px;" "border-radius: 15px;" "border-color: red;" "padding: 10px;" "}" "QPushButton:checked{" "border-top-color:qlineargradient(spread:pad,x1: 0, y1: 0, x2: 0, y2: 1," "stop: 0 #000000, stop: 1 #c2c2c2);" "border-left-color: qlineargradient(spread:pad,x1: 0, y1: 0, x2: 1, y2: 0," "stop: 0 #000000, stop: 1 #c2c2c2);" "border-right-color: qlineargradient(spread:pad,x1: 1, y1: 1, x2: 0, y2: 1," "stop: 0 #000000, stop: 1 #c2c2c2);" "border-bottom-color: qlineargradient(spread:pad,x1: 1, y1: 1, x2: 1, y2: 0," "stop: 0 #000000, stop: 1 #c2c2c2);" "}" ); 

The result of the program:

enter image description here

    1 answer 1

    You need to enable anti-aliasing in a QPainter object using the setRenderHints method. This is usually done when overriding the paintEvent. method paintEvent.

    You will need to create a class that will intercept events. You will install the filter class using QObject::installEventFilter . Then you need to create a QPainter object, in the constructor of which you will transfer the original object. ( QWidget includes QPaintDevice )

     filter::eventFilter(QObject* obj, QEvent* event) { QPainter painter(static_cast<QWidget *>(obj)); painter.setRenderHint(QPainter::Antialiasing, true); 
    • The sequence of actions is not clear. And use "setRenderHints" or "setRenderHint"? - Taras