I have a few labels I want to sometimes look grayed-out, depending on some variable. Some of those labels have effects (such as changing those factors) when clicked. I'd like my program to look good regardless of what theme the user is using, so I can't hardcode the colors. How can I do this?
I can think of several solutions, but all of them have some annoying drawbacks:
Change the text color: Sounds like the easiest solution, but it's a bit harder since I want to support theming/palettes. Especially if the system theme is changed while the program is running, since then I'd have to update the palette again.
Call setDisabled() and override event: That just feels wrong, and also risks overriding platform behavior.
Make a custom text widget: Would be possible, of course, but it would require either a lot of code duplication and wasted time, or be a rather half-assed and limited implementation.
Wrap paintEvent with a pair of setDisabled() calls: No. Just no. Also, I don't know if that would work with concurrency.
You can just set the style sheet of this label, since it's a Widget. It works for me and when themes are changed because of OS switching or whatever, it keeps the same.
label.setStyleSheet("color: gray")
The style sheet have a CSS syntax. You can make wonderful things with it, just have a look on the reference properties and some examples for some distinct widgets.
Copy the brushes from the "Disabled" palette role to the "Active" role:
palette = mylabel.palette()
palette.setCurrentColorGroup(QtGui.QPalette.Disabled)
palette.setColorGroup(QtGui.QPalette.Normal, palette.windowText(),
palette.button(), palette.light(), palette.dark(), palette.mid(),
palette.text(), palette.brightText(), palette.base(), palette.window())
mylabel.setPalette(palette)
mylabel should now look like it's disabled, but it's actually not.
This should work for any widget, not just labels.
Related
I've been struggling with learning how to use stylesheets to customize the look of my widgets in Qt.
For example, after much effort, I just figured out that the name of the property that determines what color the text on a QComboBox drop-down menu is when it is mouse-over'd is selection-color, and the background color is selection-background-color. But most of that I discovered by random guess-and-check.
Where can I find documentation that will actually tell me these things so I don't have to guess? Does Qt follow some sort of standard naming convention?
http://doc.qt.nokia.com/latest/stylesheet-reference.html
http://doc.qt.io/qt-5/stylesheet-examples.html
The above link gives examples for pretty much every control. For the combobox it mentions the QAbstractItemView, and mentions that you need selection-background-color etc... to style it - with an example.
It doesn't always explain what each property does however, which is where the doc that baysmith linked to comes in.
So with these two documents together you should be in good shape.
I'd like to add visual emphasis to a selected UI component by de-emphasizing everything around it, e.g. make everything around it blurry, or more transparent, or something similar.
Two questions, really:
spec: what effect would you use do build something like this? Do you know of any software that does this well?
implementation: what is the most obvious approach to apply a blur, or change alpha, to everything around a specific component?
thank you all!
If you display the component using the PopUpManager, everything else will 'blur' out on it's own. You won't be able to interact with it, though.
I you don't want to use PopUpManager, then manually disable everything but the component you want to highlight. This could be dead simple, or could be horribly complex depending on your architecture and how components are laid out in relation to the component you want to highlight.
If you don't want to disable a component, but do want the disabled 'look', then most Spark components have 'disabled' SkinState. You could copy the design to the active state, or create a new state for your "not de-activated even though it looks like' state.
I wanted to consult with the sages here regarding Qt and skinning, get your opinion and chart a path for my development. My requirements are as follows:
My Qt/C++ application (cross platform with Mac, Windows and Linux versions) needs to have modular skins.
A skin is defined as a set of one or more elements: - Window background texture - Look/feel of UI controls such as edit boxes, drop down, radio buttons, buttons etc. - Look/feel of window "caption", resize grips etc.
Skins will be installed with the application installer, allowing the user to choose which one he/she wants to use. Users should be able to change skins on the fly.
Can I go the QML route? should this be custom and based on simple resources which are built into the application? Any design advice will be appreciated.
Thanks.
If I understood you correctly then stylesheet is the best way forward. You can create stylesheets similar to CSS and then pass them as command line option to your application or load on invocation to style your application at runtime. That way you can create multiple stylesheets each having a different look and feel and allow user to load them at will. Since its CSS it doesn't need any new learning and you can keep all your styling outside your source code.
Here are a list of resources that can get you up and running quickly:
http://blog.qt.io/blog/2007/11/27/theming-qt-for-fun-and-profit/
http://doc.qt.io/qt-5/stylesheet.html
I haven't played with QML yet, but you could also create a custom QStyle implementation that supports your resource format. Note that you'd lose style sheet support if you went this route.
Changing window captions is a little trickier if you want portability.
QML, if I understand correctly, doesn't really skin the widgets, it mainly deals with GUI layout etc etc.
QStyle is used to change the looks. It is a bit low-level though, and requires programming, so if you want to load different user-created skins (from an XML or so) it might be tricky to support extensive skinning. Chaining colors and a few items are easy enough though. (There might be someone else who've done something you could re-use.. not sure.)
For modifying widgets, use QStyle::polish(). You could use that to change the background picture (if it's a top-level window, or of a certain class). There are numerous repaint method to change almost every part of every widget.
Store/load the style using QSettings, by reading and setting the desired Style just after QApplication but before your main window is constructed.
I have Qt dialogs which need to adjust for a different locale at runtime.
The locale is set once at program startup and doesn't change.
I need to change both the label text and the ORDER of some text input boxes.
eg. Text boxes are day,month,year or month,day,year.
Is there a common/simple way to do this?
(note - it's not a simple date control, it's a complex industry specific thing. The date is just an example.)
If you are looking for a full automatic way to handle this, it would be too complicated because of a lot of scenarios and requirements.
A simple and intuitive way is to use QStackedWidget and put different layout on separate stacks, activate one stack according to locale at runtime. But how to handle the events or acquire data? embeded UI may help.
Has anybody experience in building a custom style in Qt? What I have in my mind is a complete new style that affects all kind of widgets. I have seen some examples in the web for a custom combo box. But I have no idea how much time and code it takes to build a "complete" new custom style ... maybe someone can give me a hint.
We think of using Qt 4.3 (or even newer) ...
Check out the Stylesheets facility in Qt 4. While it's still a hassle, it's way easier than doing a full-on custom style. You can just adjust one visual facet at a time and try it out.
It pays attention to inheritance. So if you style the font in QWidget, then every visual widget will also use that font. And so on.
I have developed a "new" style that changed the appearance of much of an application. It did take some time, and quite a bit of experimentation. I also derived my style from the generic windows style, to allow it to handle some of the stuff I didn't want to mess with. All told, I think it took me a week to get most of what I wanted, with practically no prior exposure to the styles.
In order to actually develop one, I would get into the source for their styles example, which has a "wood" style. I put my own style in place of the example style, and started changing things while using the example program to check how it looked. Depending on how you are developing it, you might want to have a configuration file so you can easily change some of the values without recompiling.
You might want to look at existing styles. You can find quite a few of them on kde-look.org, in the Styles / 4.0 section.
We've done it in the past (in Qt 3), and it's extremely time-consuming. We had a lot of problems with flickering, redraws not working the way we expected, sluggish behavior, bugs in the Qt implementation. It a lot less straight-forward than it seems, and there's little support or user experience too. Unless you need something really particular (as we did), I'd say it's not worth the trouble.
Other frameworks are supposed to make it easier (some Java-based?), but I don't have first hand experience.
If you don't need to radically change the widget style, you might want to try using widget style sheets:
http://doc.qt.digia.com/4.4/stylesheet.html