1.1当要设置QPushbutton按钮背景,字体颜色,鼠标滑过状态,鼠标单击后状态时,可以用QSS来设置,具体的代码如下:
QPushButton *allSelect = new QPushButton; allSelect->setStyleSheet("QPushButton{border-image: url(:/res/appicon/wx.png) 0 0 0 0;border:none;color:rgb(255, 255, 255);}" "QPushButton:hover{background-color: rgb(20, 62, 134);border:none;color:rgb(255, 255, 255);}" "QPushButton:checked{background-color: rgb(20, 62, 134);border:none;color:rgb(255, 255, 255);}");
1.2另一种设置按钮图标显示。下面代码功能是在一个按钮内显示图标和文字,效果为左图标,右文字。当鼠标滑过时图标切换为另一个图标。当点击鼠标后又切换到另一个图标。具体代码如下:
QPushButton *readyRecoveryBtn = new QPushButton("准备恢复"); readyRecoveryBtn->setFixedSize(QSize(95,20)); readyRecoveryBtn->setStyleSheet("QPushButton{background-image: url(:res/recoverydata/icon/main_icon_recovery.png);background-repeat: no-repeat;background-position:left;border:none;color:rgb(255, 255, 255);}" "QPushButton:hover{background-image: url(:res/recoverydata/icon/main_icon_recovery_h.png);background-repeat: no-repeat;background-position:left;border:none;color:rgb(255, 255, 255);}" "QPushButton:pressed{background-image: url(:res/recoverydata/icon/main_icon_recovery_p.png);background-repeat: no-repeat;background-position:left;border:none;color:rgb(255, 255, 255);}");
原文 :https://blog.csdn.net/naibozhuan3744/article/details/80913651