天天看點

QPushButton的使用

1、顯示

basePushButton* infoTitleBtn = new QPushButton;
    infoTitleBtn->setText(“一個按鈕”);
    infoTitleBtn->setFixedSize(100,30);
    HLayout->addWidget(infoTitleBtn);
           

2、樣式設定

infoTitleBtn->setStyleSheet("QPushButton{"//正常狀态樣式
                                "background-color:rgba(239,243,248,1);"//背景色(也可以設定圖檔)
                                "border-width:2px;"                     //邊框寬度像素
                                "border-radius:5px;"                    //邊框圓角半徑像素
                                "border-color:rgba(239,243,248,1);"    //邊框顔色
                                "font-size:16px;"                       //字型,字型大小
                                "color:rgba(41,48,59,1);"               //字型顔色
                                "}"
                                "QPushButton:pressed{"//滑鼠按下樣式
                                "background-color:rgba(52,133,253,1);"
                                "border-color:rgba(255,255,255,0);"
                                "border-style:inset;"
                                "color:rgba(255,255,255,1);"
                                "}"
                                "QPushButton:hover{"//滑鼠懸停樣式
                                "background-color:rgba(52,133,253,1);"
                                "border-color:rgba(255,255,255,0);"
                                "color:rgba(255,255,255,1);"
                                "}");
           

3、設定提示内容

infoTitleBtn->setToolTip("提示内容");
           

4、設定不可點選狀态

infoTitleBtn->setEnabled(false);
           

繼續閱讀