chacham15
chacham15

Reputation: 14251

How can I modify an existing Qt stylesheet?

For example:
if I want to create buttons, which, when pressed, each modify a single aspect of the stylesheet:

The trick here, though, is that I don't want to store all the variables and rebuild the style sheet on each button press. I would like, for example, to have a simple:

this->setStyleSheet(this->getStylesheet()+"margin-left: 10px:")

Upvotes: 1

Views: 6681

Answers (1)

s4eed
s4eed

Reputation: 7891

Here is the code in main.cpp:

QWidget wdg;
QHBoxLayout hlay;
wdg.setStyleSheet("border:2px solid rgb(74, 74, 74);");

QPushButton btn;
btn.setStyleSheet("border-radius:5px;");
btn.setText("Hello");

QPushButton btn2;
btn2.setStyleSheet("background-color: rgb(190, 190, 190);");
btn2.setText("Hello");

hlay.addWidget(&btn);
hlay.addWidget(&btn2);

qDebug()<<btn.styleSheet();

wdg.setLayout(&hlay);
wdg.show();

Setting and getting the style sheet works with QString, and so, you can use + operator.

Upvotes: 2

Related Questions