Qt的个性化

  学习Qt不久,Qt的个性化初级看来有两种方法,一是setStyle()函数,Qt内置了几种风格可以使用,例如QWindowsStyle,QCleanlooksStyle等,代码片段如下

QStyle *style=new QCleanlooksStyle();
QPushButton *b=new QPushButton(this);
b->setStyle(style);

第二种方法我觉得更强大也更好用,是setStyleSheet()函数,不仅可以设置控件的背景颜色和背景图片,还可以设置不同状态下的属性,例如QPushButton被按下的时候。代码片段如下

QPushButton *b=new QPushButton(this);
b->setStyleSheet("QPushButton{background-color:green;background-image:url(:/new/001.bmp)}QPushButton:pressed{background-color:yellow}");

原文地址:https://www.cnblogs.com/jwchen08/p/5942558.html