QT - CSS: decoration on focus

后端 未结 5 495
深忆病人
深忆病人 2020-12-03 14:23

I\'m experimenting a bit with CSS for making a cool user interface for my QT application.

I have this problem: I have a QPushButton and when it is on focus it has a r

5条回答
  •  失恋的感觉
    2020-12-03 15:09

    I ran this snippet of code both on Windows 7 (Qt5) and on Ubuntu 12 (Qt4.8). There are no problems with it:

    QFile file("style.css");
    if(file.open(QIODevice::ReadOnly))
    {
      QString data = file.readAll();
    
      // "this" is the derived QMainWindow class
      this->setStyleSheet(data);
    }
    

    And alternatively...

    ui->pushButton->setStyleSheet("QPushButton"
                                  "{"
                                  "color: #b1b1b1;"
                                  "background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #565656, stop: 0.1 #525252, stop: 0.5 #4e4e4e, stop: 0.9 #4a4a4a, stop: 1 #464646);"
                                  "border-width: 1px;"
                                  "border-color: #1e1e1e;"
                                  "border-style: solid;"
                                  "border-radius: 6;"
                                  "padding: 3px;"
                                  "font-size: 12px;"
                                  "padding-left: 5px;"
                                  "padding-right: 5px;"
                                  "}"
                                  "QPushButton:pressed"
                                  "{"
                                  "background-color: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #2d2d2d, stop: 0.1 #2b2b2b, stop: 0.5 #292929, stop: 0.9 #282828, stop: 1 #252525);"
                                  "}"
                                  "QPushButton:hover"
                                  "{"
                                  "border: 2px solid QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #ffa02f, stop: 1 #d7801a);"
                                  "}"
                                  );
    
    qDebug() << ui->pushButton->styleSheet();
    

提交回复
热议问题