Тарас
Тарас

Reputation: 71

Change in styleSheet

How to change in QPushButton only one item with setStyleSheet? The word "item" or "element" I mean "background-color", "border-color", "border-radius", and so on. If you do so:

setStyleSheet("QPushButton {"
                  "background-color: blue;"
                  "}");

the remaining elements (border-radius, ...) will default. And I want to change only one of elements, the other do not touch. For example, I have QPushButton with stylesheet like so:

setStyleSheet("QPushButton {"
                      "background-color: blue;"
                      "border-radius: 5";
"}");

if I want to change border-radius this way:

setStyleSheet("QPushButton {"
                          "border-radius: 10";
    "}");

I also change background-color to default value, but I want to change only border-radius (other elements I do not change).

Upvotes: 0

Views: 87

Answers (1)

LogicStuff
LogicStuff

Reputation: 19607

From Qt Style Sheets Examples:

If we want the property to apply only to one specific QLineEdit, we can give it a name using QObject::setObjectName() and use an ID Selector to refer to it:

myDialog->setStyleSheet("QLineEdit#nameEdit { background-color: yellow }");

Always search through Qt's documentation first. It's one of the best I've seen.

Upvotes: 3

Related Questions