How to add style via setStyleSheet () without losing orignal style in Qt?

I Konw I can use setStyleSheet () to set the style in Qt. But I ran into a problem when I used setStyleSheet () for the two times lost first styles, which is set using the first use of setStyleSheet () .

For exmaple ,

setStyleSheet("QLabel{color:red;}");

............

setStyleSheet("QLabel{border-image:url(……)}")

When I set border-image, the red color property is lost.

I tried to solve this problem using

setStyleSheet(styleSheet()+QString("QLabel{border-image:url(……)}"));

but it was the same that only the border-image property existed.

Do I have to add every property of the style when I use setStyleSheet (), although I set it before.

Thank you for bringing my poor written English. All tips will be appreciated.

+4
2

QLabel:

setStyleSheet("color:red;");

, :

setStyleSheet( styleSheet().append(QString("border-image:url(……);")) );
+5

.

, ( ). , ++ .

parentWidget->setStyleSheet( "QLabel#yourLabel { color:red; }" );
yourLabel->setStyleSheet( "QLabel { border-image:url(...) };" );

, .

, , . , .

+5

Source: https://habr.com/ru/post/1539408/


All Articles