QPushButton gradient



  • How do you smooth the gradient on 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);"
                    "}"
                    );
    

    Programme performance result:

    введите сюда описание изображения



  • We've got to turn the lighting on the facility. QPainter using setRenderHints Method. This is usually done when the method is changed paintEvent.

    You'll need to create a class that will intercept events. Class filter set by QObject::installEventFilter♪ Then we need to create the object. QPainterthe original object will be handed to the designer. (sighs) QWidget includes QPaintDevice)

    filter::eventFilter(QObject* obj, QEvent* event) {
    QPainter painter(static_cast<QWidget *>(obj));
    painter.setRenderHint(QPainter::Antialiasing, true);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2