QT中使用setStyleSheet()设置空间的样式表是很常用也很方便的方式。使用方法如下
工具/原料
QT开发工具
方法/步骤
首先要定义一个QPushButton对象
QPushButton button = new QPushButton();
设置button的字体类型、字体大小和字体颜色代码如下:
button->setStyleSheet"QPushButton{ font-family:'Microsoft YaHei';font-size:12px;color:#666666;}");
设置button的状态图片:正常、鼠标移入、鼠标点击状态的图片切换。代码如下:
button->setStyleSheet( "QPushButton{border-image: url(Resources/images/BreadCrumbNavigation/navigation_more_normal.png);}" "QPushButton:hover{border-image: url(Resources/images/BreadCrumbNavigation/navigation_more_hover.png);}" "QPushButton:pressed{border-image: url(Resources/images/BreadCrumbNavigation/navigation_more_pressed.png);}");
也可以同时设置这两种属性:
button->setStyleSheet( "QPushButton{font-family:'Microsoft YaHei';font-size:12px;color:#666666;}”
border-image: url(Resources/images/BreadCrumbNavigation/navigation_more_normal.png);}" "QPushButton:hover{border-image: url(Resources/images/BreadCrumbNavigation/navigation_more_hover.png);}" "QPushButton:pressed{border-image: url(Resources/images/BreadCrumbNavigation/navigation_more_pressed.png);}");