下面的內容都是我從網上自己總結的:
1 btn1=new QPushButton(this);
btn1->setStyleSheet("QPushButton{color:red;background:yellow}"); //設定前景顏色,就是字體顏色
// btn1->setStyleSheet("QPushButton{background:yellow}");
2 btn2=new QPushButton(this);
btn2->setStyleSheet("QPushButton{color:red;background-color:rgb(200,155,100)}");//使用rgb來設定背景顏色
3 btn3=new QPushButton(this);
btn3->setStyleSheet("QPushButton{background-image:url(image/1.png);background-repeat: repeat-xy;background-position: center;
background-attachment: fixed;background-clip: padding}");
btn4=new QPushButton(this);
btn4->setStyleSheet("QPushButton{border: 3px solid red;border-radius:8px}"); //設定邊框寬度以及顏色
其中:
//border-image用來設定邊框的背景圖片。
//background-repeat可以設定背景圖片的重復規則,這里設定僅在xy方向都重復,所以圖片會被重復一次
//background-position用來設定圖片的位置,是左(left)還是右(right),還是在中間(center),是上(top)還是底部(bottom)
//background-attachment用來這定背景圖片是否卷動或者和窗口大小相匹配,默認是卷動的
//border-radius用來設定邊框的弧度。可以設定圓角的按鈕
下面是效果圖:
