M.Weiss
M.Weiss

Reputation: 59

How to set the button's style sheet to have several properties?

btn.setStyleSheet("QPushButton {font: 30pt Comic Sans MS"}
btn.setStyleSheet("background-color: red")

I am trying to get my "btn" to be both red and a specific font and size, but can only get one style at a time, in this case; the red command overides the font command.

How can I merge these commands so both are executed?

Upvotes: 0

Views: 1768

Answers (2)

M.Weiss
M.Weiss

Reputation: 59

Solved it:

btn.setStyleSheet("background-color: red;"
                        "font: bold 30pt Comic Sans MS")

to merge the commands! Thanks!

Upvotes: 1

Luca9504
Luca9504

Reputation: 3

I don't know if this is actually the code you have but you didn't close the brackets for the method nor the double quotes

So this:

btn.setStyleSheet("QPushButton {font: 30pt Comic Sans MS}
btn.setStyleSheet("background-color: red")

Will become this:

btn.setStyleSheet("QPushButton {font: 30pt Comic Sans MS}"}
btn.setStyleSheet("background-color: red")

Try it, but anyway check this document to reference your code to: http://doc.qt.io/qt-4.8/stylesheet-examples.html

Upvotes: 0

Related Questions