qtdesigner设置按钮样式,如何正确设置QPushButton的颜色?

I can successfully change the color of a QPushButton using setStyleSheet, but because I'm using QT Creator to make the GUI, every time I run qmake and make, the calls to setStyleSheet disappear.

Changing the palette of the button doesn't change its color either.

What's the best way to change to color of the button without having to manually change my ui_window.h file every time I qmake?

解决方案

Using style sheets is the right way to do, no matter you're using Qt Creator or not.

From what you are discribing, it seems you are writing yourself some code into the ui_window.h, which is the wrong way to set the stylesheet.

You can set it in the constructor of your window class, or set it from the GUI editor (Qt Designer) :

double-clic on your window.ui in the project tree displayed by Qt Creator.

select your QPushButton in the GUI editor.

locate the styleSheet property in the properties editor.

clic on the three dots (...) : this will bring a stylesheet editor.

If you set the stylesheet with the stylesheet editor, nothing will disappear each time you are rebuilding your app.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值