Qt的控件的样式表设置

  可以在控件属性里设置

 1.可以在代码里设置PushButton为圆角背景色 : 

ui->pushButton_close->setStyleSheet("QPushButton{border:2px groove gray;border-radius:4px;padding:2px 4px;background-color: rgb(225, 225, 225);}");

   1).当要设置QPushButton按钮背景,字体颜色,鼠标滑过状态,鼠标单击后状态时,可以用QSS来设置,具体的代码如下:

allSelect->setStyleSheet("QPushButton{border-image: url(:/res/appicon/wx.png) 0 0 0 0;border:none;color:rgb(255, 255, 255);}"
                            "QPushButton:hover{background-color: rgb(20, 62, 134);border:none;color:rgb(255, 255, 255);}"
                            "QPushButton:checked{background-color: rgb(20, 62, 134);border:none;color:rgb(255, 255, 255);}");

   2).设计的一个比较好的效果,要想在编辑样式表里添加则去掉每行的  " " 双引号即可 : 

 

ui->pushButton_save->setStyleSheet("QPushButton{background-color: rgb(225, 225, 225);border:2px groove gray;border-radius:4px;padding:2px 4px;border-style: outset;}"
                                       "QPushButton:hover{background-color:rgb(229, 241, 251); color: black;}"
                                       "QPushButton:pressed{background-color:rgb(204, 228, 247);border-style: inset;}");

   3).设计的修改了一点效果,减少了3D的凸起效果 :

ui->pushButton_add->setStyleSheet("QPushButton{background-color: rgb(225, 225, 225);border:1px groove gray;border-radius:4px;padding:1px 4px;border-style: outset;}"
                                      "QPushButton:hover{background-color:rgb(229, 241, 251); color: black;}"
                                      "QPushButton:pressed{background-color:rgb(204, 228, 247);border-style: inset;}");

   在编辑样式表里添加如下一样的效果(写这个是为了方便我复制) :

QPushButton{background-color: rgb(225, 225, 225);border:1px groove gray;border-radius:4px;padding:1px 4px;border-style: outset;}
                                       QPushButton:hover{background-color:rgb(229, 241, 251); color: black;}
                                       QPushButton:pressed{background-color:rgb(204, 228, 247);border-style: inset;}

   

   2.设置QWidget窗口的样式表代码 :

   1).设置QWidget窗口的四个角为圆角 :

QWidget{border-top-left-radius:15px;border-top-right-radius:5px;border-bottom-left-radius:15px;border-bottom-right-radius:5px}

摘抄自 : 各大平台网站 ...

猜你喜欢

转载自blog.csdn.net/Superman___007/article/details/88713914