admin管理员组文章数量:1794759
QPushButton使用css设置图标和文本
平时我们设置QPushButton时只设置它的normal, hover, pressed三种状态的文本类型或者背景图片,很少用到图标和文本同时显示,本篇介绍图标和文本同时显示,并且图标可以动态调整显示位置,下面是具体的代码:
void MainWindow::initView() { ui->pushButton->setStyleSheet("QPushButton{background-color: #66ffff;border-radius:5px;" "background-image: url(:/arrow_refresh16.png); " "background-origin: content;background-position: center;" "padding-right: 40px; padding-bottom: 2px; background-repeat: no-repeat;" "text-align:top;padding-left: 2px;padding-top: 2px;" "font-size: 12px; color: #FFFFFF;}"); ui->pushButton_2->setStyleSheet("QPushButton{background-color: #66ffff;border-radius:5px;" "background-image: url(:/arrow_refresh16.png); " "background-origin: content;background-position: center;" "padding-right: 40px; padding-bottom: 2px; background-repeat:repeat;" "text-align:top;padding-left: 2px;padding-top: 2px;" "font-size: 12px; color: #FFFFFF;}"); ui->pushButton_3->setStyleSheet("QPushButton{background-color: #66ffff;border-radius:5px;" "background-image: url(:/arrow_refresh16.png);" "background-origin: content; background-position: top;" "background-repeat: no-repeat;" "text-align: bottom; padding-bottom:5px;" "font-size: 12px; color: #FF0000;}"); ui->pushButton_4->setStyleSheet("QPushButton{background-color: #66ffff;border-radius:5px;" "background-image: url(:/arrow_refresh16.png);" "background-origin: content; background-position: bottom;" "background-repeat: no-repeat;" "text-align: top; padding-top:5px;" "font-size: 12px; color: #FF0000;}"); ui->pushButton_5->setStyleSheet("QPushButton{background-color: #66ffff;border-radius:5px;" "background-image: url(:/arrow_refresh16.png);" "background-origin: content; background-position: left;" "background-repeat: no-repeat;" "text-align: right; padding-right:5px;" "font-size: 12px; color: #FF0000;}"); ui->pushButton_6->setStyleSheet("QPushButton{background-color: #66ffff;border-radius:5px;" "background-image: url(:/arrow_refresh16.png);" "background-origin: content; background-position: right;" "background-repeat: no-repeat;" "text-align: left; padding-top:5px;" "font-size: 12px; color: #FF0000;}"); }运行效果:
css的参数参考:
CSS padding 属性
CSS text-align 属性
CSS3 background-origin 属性 | 菜鸟教程
本文标签: 图标文本QPushButtoncss
版权声明:本文标题:QPushButton使用css设置图标和文本 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686971446a123927.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论