Dynamically change QStyle at runtime? - qt

I want to tweak the existing style at runtime, specifically QStyle::PM_ToolBarIconSize. Can this be done? As far as I can tell, you can only inherit QStyle and override pixelMetric().
Edit 1: In the specific case of QStyle::PM_ToolBarIconSize, I could use QToolBar::setIconSize, but that would set the icon size for just a single toolbar instance. I want to change the underlying style hint to affect all toolbars everywhere with one fell swoop. And QStyle::PM_ToolBarIconSize may not be the only style I want to tweak, it's just the first one I'm looking at that just so happens to have a "change this instance's icon size" function.
Edit 2: I can't just make a new style subclass because the current style is already a custom style based on style sheets. There are several styles that a user can choose from. I don't want to create a bunch of new styles just so I can tweak a couple of toolbar icon or menu height size settings.

This is the exact purpose of QProxyStyle.

Why not overriding QStyle then? Your subclass would return an icon size (via pixelMetric) which depends on a settable parameter of your QStyle.
As Qt does not have a dynamic QStyle mechanism, it is better to create a new style instance with the changed icon size, then set it to the QApplication, rather than altering the current style.

Related

Qt Designer button image change while keeping windows style?

I can change the image or any other style of a QPushButton in the designer by changing the stylesheet, but any change in the style sheet changes all the other properties.
For instance, when I change the border image everything else is changed and it does not inherit the rest of the properties from the parent (or windows style).
How can I keep the windows style while changing only the image?
From How can I set Styles to a QTabwidget without overwriting existing styles in QT ?:
A style sheet is all or nothing. so if u all apply style sheet, it
might sort of reset the look for some widgets and to fix that, you
must supply a full stylesheet.
The key parts are:
A style sheet is all or nothing.
you must supply a full stylesheet.
You can set an image for the QPushButton from the code or by using QtDesigner like this:
Select the button
In the properties window set the image and the
size (properties icon and iconSize).
Did you try set style to the single push button:
your_push_button_pointer->setStyleSheet(
"QPushButton{background-image: url(:/images/call_up.bmp);}"
"QPushButton:hover{background-image: url(:/images/call_hov.bmp);}"
"QPushButton:pressed{background-image: url(:/images/call_down.bmp);}");

How to change the style of Mpart tab in RCP application by css?

I have an application where I want to set the color of a tab dependent on the displayed data, using an id or a tag.
I could only find examples on how to set the color of selected and unselected tabs. Is there another built in possibility for styling tabs, or will I need an own renderer?
Note:My partstack has so many mpart and for each mpart tab i want to set color depending on data.
There isn't any way to do this with the standard CSS support.
You will have to use the e4 CSS swt-tab-renderer property to define a new tab renderer, probably based on the e4 org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering renderer. Even then I think this will be difficult.
You also use the org.eclipse.e4.ui.css.core.propertyHandler extension point to define new CSS properties.
The org.eclipse.e4.ui.css.core.elementProvider extension point allows you to define new CSS pseudo classes (such as :active) but this might be difficult to use in this case because an element provider is already defined.

Firemonkey how to change a style property in a Stylebook

I have created a Stylebook component that has a toolbarstyle. All toolbars in my app have this stylelookup. This style consists of a TLayout filled with a TRectangle that has the stylename "background" that has the color red by default.
I want to let the user set the color of the toolbar with a TComboColorBox.
So when they choose a Color I want all the toolbars to change to the color they have picked.
Now I already know how to change the style for a single toolbar, but I don't want to set the property for each individual toolbar. With the code below I can change the style color for a single toolbar.
ToolBar1.StylesData['background.Fill.Color'] := ComboColorBox1.Color;
How can I do the same for all my toolbars at once? I gues change the StyleBook but how. Also the stylebook from my MainForm get's loaded in all my other forms too, so I also don't need to change it on every form.

What are the properties of the QToolbar style that I can change?

I have a QToolbar which I have applied style to:
sMainWindowStyle += "QToolBar::handle { image: url(:/icons/toolbar_handle.png); }\n";
However as well as changing the toolbar's handle I want to change the expand arrow >>
I am unable to find a list of properties, so that I can look up what the toolbar expand arrow is. Does anybody know of a definitive list of style properties in Qt?
You can change the expand button with the following CSS.
QToolButton#qt_toolbar_ext_button
{
qproperty-icon: url(:/path/to/image.png);
}
Unfortunately the best way I know to find out which properties you can set, is to browse through the Qt source code. Some styles can even not support some properties, other styles do.

Flex LinkBar: how to set a selected button's background color?

I was able to set the text color of a selected LinkBar button by "disabledColor" style of LinkBar. Accordingly, I expect to set the background color of the selected button by "backgroundDisabledColor" style, however, it didn't work; and except "backgroundDisabledColor", I didn't see any other style that could possibly achieve this. Please help. Thanks.
The problem is probably that you're setting the style on the LinkBar itself - try setting the LinkBar's linkButtonStyleName style to a different style selector that contains all of the styles you need for your button. You should be able to set the fillColors style of the buttons themselves there - this will change the default look of the button.
If you need to adjust the "selected" color or if you need something more advanced than just skinning the button background you'll need to write a custom skin class. This isn't too difficult - the Button class has a whole set of "Selected" styles - selectedDownSkin, selectedUpSkin, selectedDisabledSkin, etc. IMO the best practice is to set your button skin to a custom skin class that sets the different individual styles based on state.
David Flately illustrates this method here. Check out his source - that should get you what you need. A good book on this topic that has this sort of thing along with lots of other examples is Juan Sanchez and Andy McIntosh's Creating Visual Experiences with Flex 3.0. I can't post a link to it because my reputation isn't high enough here yet, but you can find it on amazon or barnes and noble or any other online bookstore.
FYI - answer here....
http://dezeloper.wordpress.com/2010/02/24/flex-css-linkbar-togglebuttonbar-selected-text-color/
Haha, was looking for same thing, you can see on the source code of LinkBar:
// Hilite the new selection.
child = Button(getChildAt(selectedIndex));
child.enabled = false;
Which is clever!!! Rather than set selected to true, they disable the selected button ... why not ;-( Took me half an hour to understand the Flex team logical ...
eBuildy, Flex Specialists

Resources