Is it possible change one particular attribute in style sheet without calling setStyleSheet again? Some easy cases I solved by using attribute selectors (similar to CSS) and custom properties that define "type" or "state" of widget.
Let say I need to change border width in run-time.For that I should change attribute "border", and I have defined a custom property borderWidth of type int. CSS does support pseudofunction attr() that could used to compute value of one attribute from another. Apparently it doesn't work with Qt style sheet, e.g.
QTablo [state="3"] {
border: attr(qproperty-borderWidth);
}
after unpolish();polish();update(); routine I see no no changes. Is there a workaround for this other than to set style?
Note that Qt only supports a subset of CSS2, attr() seems to be first mentioned in CSS2.1.
You could:
Use a QFrame and change its properties, instead of using a style sheet.
Generate the stylesheet at run time and assign it. Something like QString("border-width: %1px;").arg(borderWidth);.
Use a custom QProxyStyle that returns the correct value in pixelMetric().
Related
I am not sure how to do this.
I am using a table to create a data dictionary.
For each data item name, if it has a certain tag value, I'd like to change the color and italicize the font. How do I accomplish this?
Sadly, you can't (easily). The font can only be changed from the context menu for a single diagram element (either globally of for the very diagram). Shape script does not offer changes to the font. Only the color can be changed with SetFontColor. In any case, a font change affects any text in a diagram element. You can not highlight e.g. a single attribute.
What can be done is to implement an add-in that can change the font for single elements based on some implemented rule. The easiest would be to run a "global-change" macro that goes through all diagram-/elements and sets the font.
Is there a simple way to obtain inherited stylesheet for a widget, if stylesheets were set in its parents (some levels above)? stylesheet() would return local value of property only.
In theory, to obtain text of effective stylesheet, I have to walk up to the topmost parent, then concatenate found styles, in order of parenthood. I was wondering if there is simpler way, library ALREADY does same thing. Problem is that concatenation doesn't work right with local stylesheets that do not have a selector in them
QWidget::styleSheet() call would return only the text for particular widget if set. Stylesheet is result of syntax parsing of that text, do I need to create my own parser of style sheet, that have to recreate way , how Qt work?
The solution indeed is either to create a parser and a generator, or use so an external source to generate style sheets. I ended up with an xml parser which was creating style sheet definitions for all widgets from a single configuration file, which was simpler to do and less error-prone.
For my aplication I use qStylesheet. In a custom widget I draw some things overriding the paintevent method. I want to use the colors of this widget, set by the qStylesheet to achieve consistency, and later on configurability. How can I get the properties set by the qStylesheet?
Try to get QPalette and get current properties. For example:
widget.palette().brush().color();
Another way is to get stylesheet and parse it (maybe with regular expressions), but I think it is not the best approach.
I need to change between two styles in my app: custom, stylesheet and default one. I tried to change it by:
qApp->setStyle(new QCleanlooksStyle);
but it doesn't change the colors, images, etc.
You can invoke setStyleSheet with an empty string.
qApp->setStyleSheet( "" );
Setting the style and setting the stylesheet are two different things.
If you have an application-wide stylesheet, that is, you called QApplication::setStyleSheet(), then you'll need to clear it for your setStyle() function to really have any effect:
qApp->setStyleSheet( QString() );
If, on the other hand, you have random bits of style set on your individual widgets, then you'll probably have to migrate to a global style sheet first.
Is it possible to look up stylesheet values at runtime in Qt?
I'm working on a custom button derived from QPushButton that has some stylesheet properties set. I'd like to be able to look up some stylesheet settings like border width, margin, padding-top, padding-left, padding-right, etc. Is this at all possible to do without calling widget->getStyleSheet() and parsing out the values myself?
Internally, when you call QApplication::setStyleSheet() Qt creates a QStyle sub-class called QStyleSheetStyle.
That means you can query style sheet information via the normal QStyle methods. Just remember to fill in the options and widget parameters properly to ensure you get the right values from the style sheet.
Don't think so, you might be able to find something by stepping through the drawing code. But the parsing and the application of stylesheets is pretty optimised and uses a lot of preprocessing. I don't even think that you can get to the stylesheet of a widget if it was actually set in a parent.