发布网友
共2个回答
热心网友
loginButton->setStyleSheet(tr("QPushButton{background-color:white;}QPushButton:hover{background-color:cyan;}QPushButton:pressed{background-color:red;}"));
调用Qbutton的setStyleSheet类,上面的函数实现鼠标移到按钮前是白色,移到按钮后是蓝色,按下后是红色。当然如果不想换掉按下后的颜色,直接loginButton->setStyleSheet(tr("QPushButton{background-color:white;}QPushButton:hover{background-color:cyan;}"));就行。
热心网友
首先要响应鼠标事件,然后通过 Style Sheets 改变按钮的外观
1. 从QPushButton派生一个自己的按钮类
2.在新类的构造函数中 调用 mouseTracking(true);以获取鼠标移动事件。
3. 重载 mouseMoveEvent(),在该函数中通过StyleSheet改变外观
如: setStyleSheet("background: yellow”);
Qt Style Sheets的使用请参考 Assistance中的内容 和 Style Sheet Example