天天看点

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);
           

继续阅读