开发者

Changing the color of a Push Button in QT Creator

开发者 https://www.devze.com 2023-01-29 08:41 出处:网络
How do I change a buttons color? I have found ways to do it by writing button->setStyleSheet(\"* { background-color: rgb(255,125,100) }\");

How do I change a buttons color? I have found ways to do it by writing

button->setStyleSheet("* { background-color: rgb(255,125,100) }");

in Ui_Window.h

But everytime I qmake, 开发者_运维百科the Ui_Window.h gets remade and I lose my colors.

Does anyone know how to permanently keep the colors of the button? I am working with QT Creator. If someone could direct me =D

Thanks so much!


  • Easiest way would be to use a style sheet on the button:

    backgroundColourButton->setStyleSheet("background-color: red");
    


Aero, take into account that you MUST not modify Ui_Window.h file since it is generated by Qt Designer. So, every time you recompile the .ui file, this header file will be overwriten. As I see, you are using Qt Designer to add buttons to the layout. In this case, you can right click on a widget (or in the main dialog) in Qt Designer and click then in 'Change layout...'. On there, you can do something like:

QPushButton {
    background-color: rgb(255,125,100);
}

for all buttons, or for an specific button:

#nameOfTheButton {
    background-color: rgb(255,125,100);
}

Tell me if this works for you. Cheers,


If you use your form only in one class, you may add your expression there, after calling to ui->setupUi() in it. Or even add stylesheet directly to form, look for property 'StyleSheet' in properties view of Qt designer.

0

精彩评论

暂无评论...
验证码 换一张
取 消