在没有应用任何样式的情况下,我在Qt中创建了一个QPushButton,因此它继承了来自Windows10的样式,结果如下:
然后我想临时更改按钮的颜色,所以我使用了:
pushButton->setStyleSheet("background-color: rgb(255,220,220)")
得到这个结果:
这个结果已经让我不满意了,因为它的风格和原来的略有不同。无论如何,下一步是按钮在按下时必须返回到“普通”样式,所以我添加了以下命令
pushButton->setStyleSheet("background-color: rgb(240,240,240)")
但结果与开始按钮不同:
你能给我一些建议来更好地管理这种风格吗?
谢谢
发布于 2017-09-19 16:55:00
以下是一些你可能会发现非常相似和有帮助的片段。
我有一个更新按钮,我把它变成红色的取消按钮。一旦更新操作完成或取消按下,我恢复原来的颜色和文字。
// Global variables to save off button state
QPalette update_btn_palette_restore;
QString update_btn_text_restore;
……
// Update button is pressed.
// Save the palette and text.
update_btn_palette_restore = _ui->update_button->palette ();
update_btn_text_restore = _ui->update_button->text ();
// Change the color palette and text
QPalette p=palette();
p.setBrush(QPalette::Button,Qt::red);
_ui->update_button->setPalette(p);
_ui->update_button->setText ("Cancel");
……
// Handler for when either cancel is pressed or update has finished
if(! update_btn_text_restore.isEmpty ()) {
_ui->update_button->setText (update_btn_text_restore);
_ui->update_button->setPalette(update_btn_palette_restore);
}
https://stackoverflow.com/questions/46304270
复制相似问题