Qt stylesheet

QPushButton{

border-radius:6px; //用来设定边框的弧度。可以设定圆角的按钮

border:none;         //设置无边界

font: bold;             //是否显示粗体

font-family: 微软雅黑; //设置字体所属家族

font-size: 13px;          //设置字体大小

font-weight: 20px;  //设定字体深浅

selection-color: rgb(241, 70, 62);  //设定选中时的颜色

color: rgb(255, 255, 255);  //设置前景颜色  此为白色

background: transparent;      //设置背景为透明

background-position: center;      //用来设定图片的位置, 是左( left )还是( right ), 还是在中间( center ), 是上( top )还是底部 

 

}

 

#closeBtn{

background-image: url(:/image/close.png); //添加资源图片

border-image: url(:/image/close.png); //添加资源图片

border-style: flat; //设置按钮扁平化效果

}

当设置button的icon时, 发现icon的形状并不与button一致。

设置stylesheet---> border-style: flat;  //这就是设置按钮扁平化效果

#closeBtn:hover{    //设置放置鼠标显示的资源图片

background-image: url(:/image/closeHovered.png); 

}

 

#closeBtn:checked{ //设置鼠标按下显示的图片

background-image: url(:/image/closeHovered.png); 

}

 

注: background-image 和 border-image区别?

前者是按照像素显示图片, 后者是根据窗体大小来自动缩放图片。

 

QTextEdit, QListView{

background-color: white;

background-attachment: scroll;

}

 

 

Btn= new QPushButton(tr("打开文件"), this);

Btn->setStyleSheet(

"QPushButton{background-position:left;//设置图片位于左边
background-color: rgb(33, 33, 33); //设置背景颜色
border-top-left-radius:2px;
background-repeat:no_repeat;   //设置图片不重复
text-align:right;   //设置字体位于右边
color:white;   //设置字体为白色
font-size:15px; //设置字体大小
font-family: 微软雅黑;

border-radius:4px; //设置按钮弧度
background-image: url(:/res/openFile.png);}"

"QPushButton:hover{background-color: rgb(0, 41, 88);
background-image: url(:/res/openFile_hover.png);}"

);

效果图如下:

 

 

 

 

转载于:https://www.cnblogs.com/jiangson/p/6024566.html