Undoing an added "setStyleSheet" property
-
I don't know if the CSS 'initial' and/or 'unset' values work with Qt stylesheets, might be worth a try? For example:
setStyleSheet("background-color: initial;");or
setStyleSheet("background-color: unset;");@jazzycamel
This looked good, and is a reasonable answer to the question!However, in my case both of these resulted in the
QTextEdit's going black, which is not good given that the text on it is black too :) I'm guessing that somewhere else (like the app's global stylesheet which the code reads in and applies) there is some default entry which sets allQTextEdits' default background color to something else, andinitial/unsetreverts to some other base, default color, losing that :(So a possible good answer, but in my case it really does look like I need to either remove or alter the
background-color(only) explicitly on the widget...? -
Thats a shame, maybe consider raising a feature request for that one.
Seems to me that saving and restoring the original stylesheet might be the only way to then.
-
Thats a shame, maybe consider raising a feature request for that one.
Seems to me that saving and restoring the original stylesheet might be the only way to then.
@jazzycamel
Yep, at present that seems to be the only route.setStyleSheetprinciple could do with a couple of enhancements:-
appendToStyleSheet(str). Adds some more stuff to the existing stylesheet without requiring you to fetch its current content and then reset the whole thing. Having said that, there are calls to fetch->change->settonew, so it's only really a convenience. -
From a
setStyleSheet, I assume that at some level Qt parses the properties string into its constituent properties to set. Make it so the individual properties can then be accessed directly, e.g.QWidget::setStyleProperty("background-color", newValue)orQWidget::removeStyleProperty("background-color").
At the moment, because there's only a
setStyleSheet, the code I have inherited is full of code in different modules using this, and who knows whether that will overwrite other deliberate changes from elsewhere. It doesn't lend itself to safe, self-contained programming features. -
-
@JNBarchan ,
To undo the stylesheet, you can use
textEdit->setStylesheet(""); -
@JNBarchan ,
To undo the stylesheet, you can use
textEdit->setStylesheet(""); -
Chances of this happening, apart from a contribution to Qt, are pretty slim though. The roadmap is currently fascinated with QML, customising QtWidgets is on the wayside.
@Vadi2 said in Undoing an added "setStyleSheet" property:
Chances of this happening, apart from a contribution to Qt, are pretty slim though. The roadmap is currently fascinated with QML, customising QtWidgets is on the wayside.
Although I am a total noob to Qt, I read yesterday (somewhere...) that actually the roadmap now is to sideline development on QML, because it has received so much attention, and concentrate on new features for Widgets, to bring them back up to speed!
-
@Vadi2 ,@JNBarchan
Ya, I can undo only the 1 property without altering others. I hope you got the solution.
ui->textEdit->setStyleSheet("background-color:red;font-size:12pt;");
ui->textEdit->setStyleSheet("background-color:none;font-size:12pt;");
-
@Vadi2 ,@JNBarchan
Ya, I can undo only the 1 property without altering others. I hope you got the solution.
ui->textEdit->setStyleSheet("background-color:red;font-size:12pt;");
ui->textEdit->setStyleSheet("background-color:none;font-size:12pt;");
@Vinod-Kuntoji
That does not just alter thebackground-colorproperty, as I might want. That alters the whole of the stylesheet, and relies on knowledge thatfont-sizehas been set to12ptto set that too, information which is not available to me in the generic case I have described (e.g. some other piece of code somewhere has set it, which I would not be aware of). If you read what I have asked you will see this is explained, as others understand.Furthermore (I think),
background-color:nonedoes not "undo"background-color:red: it explicitly sets it to "none", which will override the color from elsewhere, whereas in this case what I wish to do is remove the explicit specification of anybackground-coloron the widget. However, that is by-the-by to the central point described in the paragraph above. -
J JonB referenced this topic on