Domino Jachas
Domino Jachas

Reputation: 1

Why can't I set the color of a PushButton?

I've just started my adventure with Qt. After installation of QtCreator 3.6.0, the project compiled without any problems, but when I try to change PushButton colour through GUI (palette), nothing happens.

Similarly, when I substitute my own class for just added to work place (containers) widget, there's no file to swap in options. Where's the problem?

Upvotes: 0

Views: 2475

Answers (3)

Devopia
Devopia

Reputation: 670

@Domino Jachas, Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines, according to the Qt Docs.

QPalette palette = ui->pushButton->palette();
palette.setColor(QPalette::ButtonText, Qt::red); // It's ok
palette.setColor(QPalette::Button, Qt::yellow); // but, not ok. Use theme.
ui->pushButton->setPalette(palette);

Upvotes: 0

frogatto
frogatto

Reputation: 29285

You can use CSS styles. Add the following CSS style to styleSheet of your button.

QPushButton{
    background-color:yellow
}

enter image description here

Upvotes: 3

Alexander Chernin
Alexander Chernin

Reputation: 444

Click on the styleSheet property button (...). Then select a menu item "Add gradient/background-color". You can try default cover or create another one.

More detailed info here http://doc.qt.io/qt-4.8/style-reference.html

Upvotes: 0

Related Questions