Click here to Skip to main content
15,888,046 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I'm currently using Qt Designer to generate out my .ui files for development.
I noticed that there are other styles that Qt has to offer like "Cleanlooks", "Plastique" and the likes.
I was wondering if there is a means of embedding these styles into the ui file directly without the need for me to call a setStyle() at the code level.

Thanks for your help.
Posted

1 solution

Such styles are usually applied on application level and not on widgets.

At first you should decide which kind of styling you want use (style sheets or setting styles by code). They can be mixed but it is not recommended. This link may help you with the decision: https://forum.qt.io/topic/33604/style-sheets-vs-qstyle/4[^]

When using style sheets, all widgets will inherit the style from their parents (like with CSS styles for HTML). When loading a general style sheet at program start all your widgets will use it.

If you want to use different styles for specific widgets, you can enter them in the styleSheet property in the Qt Designer. That will do what you want (save the style in the UI file).
 
Share this answer
 
Comments
amsga 11-Nov-15 9:21am    
I was looking at the "Cleanlooks" style because it has a wider handle for sliders. I was wondering if I could introduce this to my .ui file so that it can be more sensitive to touch screens.
Jochen Arndt 11-Nov-15 9:35am    
You can add a style sheet definition to the widget using the styleSheet property.

But it would be better to add it to a global sheet so that all sliders will use it. You can even load such a file using the command line:
<your-app> -stylesheet=<path>

A slider example for touch screen usage (you can copy and paste it into the styleSheet property of your slider widget or its parent):
QSlider::groove:horizontal {
background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 gray, stop: 1 white);
border 1px solid white;
border-radius: 4px;
height: 10px; /* Fixed height; default is height of control */
}
/* Default height is height of groove */
/* So extent margins and set fixed width for touch screen usage */
QSlider::handle:horizontal {
background-color: white;
border: 1px solid gray;
border-radius: 3px;
margin-top: -16px;
margin-bottom: -16px;
width: 32px;
}
QSlider::handle:pressed {
background-color: orange;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900