Aero Chocolate
Aero Chocolate

Reputation: 1497

Changing the color of a Push Button in QT Creator

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!

Upvotes: 2

Views: 37284

Answers (3)

Sagar Patel
Sagar Patel

Reputation: 852

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

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

Upvotes: 6

Didac Perez Parera
Didac Perez Parera

Reputation: 3814

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,

Upvotes: 2

Raiv
Raiv

Reputation: 5781

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.

Upvotes: 0

Related Questions