Styling only promoted widgets using QT Creator - qt

I'm new to Qt and have been designing forms using Qt Creator. I've noticed that I can apply styles for specific widgets in the form's stylesheet, and it will style every widget on the form. For example "QPushButton{color: red;}" will make all the QPushButtons on the form have red text.
Is there a way to only apply styles to certain groups of widgets? For example, if I promote a QPushButton and call it MyButton, how can I set styles only for MyButtons. I would expect to be able to do something like "MyButton{color: green;}" but that doesn't seem to work.
Is there a better way to do what I'm trying to do (preferably using Qt Creator)? I can't seem to find an example of this anywhere, but maybe it's because I'm not using the correct terminology.
Thanks,
Mark

There are a lot of options for specifying selectors in style sheets. They are documented here.
One that I use (that is hinted to in the official style sheet reference document) is
|=
QPushButton[objectName|="somePrefix_"]
I use this to select items that have the same object name prefix. You could of course achieve a similar thing by applying a stylesheet to a panel containing the buttons you want to style differently but this can get tricky.

IIRC that should work, but creator might not show the preview correctly as it is not instantiating your button. Personally I think working with a global .css file that gets loaded at startup works better than applying single styles on each element in creator.
Use QApplication::setStyleSheet() to set a global stylesheet

Related

How to create a borderless table in rst2pdf?

I would like to create a borderless table in rst2pdf extension with Sphinx, but I can't seem to find a way to work around the stylesheet/css of the extension.
Any suggestions on this?
I just went through a "learning experience" with rst2pdf stylesheets, and while I may not have a complete answer for you, I think I can give you enough direction to get you started. A couple things I learned:
rst2pdf stylesheets are not CSS stylesheets, they are specific to rst2pdf and leverage (I think) some style directives from the PDF "language"; all of the source to the builtin styles can be found here
Custom rst2pdf stylesheets only need to define what styles you want to add or modify, or page templates that you want to modify
You can (and may well want) CSS and rst2pdf styles with the same name, if you want to style the same document elements differently when rendered as HTML vs. PDF
To see how the default table style for rst2pdf is defined, you can execute the command rst2pdf --print-stylesheet or you can look at rst2pdf/styles/styles.yaml - you could then create a custom style in your stylesheet like borderless-table using that information (you may even be able to use table as the value of the parent element and override the commands element, but that is just an idea). Once you have your custom style defined, you should then be able to use it in your .rst file with the class directive:
.. class:: borderless-table
+----- your table definition here ----+
Again, I haven't done this completely myself, so it's more of a partial solution or pointing in the general direction of the solution. rst2pdf is a great piece of software, but there are some devilish details that are not covered in the manual. Good luck!

How to manage clashing third party CSS

I'm working on a web application which is using Materialize as a front-end framework along with Kendo UI for the grid component.
I'm hitting problems in cases where both Kendo UI and Materialize have styles for the same element - for example they both override the styling on check boxes - this results in a broken layout due to the clash.
One option I realize is to pick either Materialize or Kendo UI and drop the other... however I would like to avoid this if possible as they in the most part have complemented each others weaknesses well.
If it was simply one element here or there putting specific overrides in would be an option however with the scale of the two frameworks this would be a maintenance nightmare as when one changed the overrides would possibly have to be refactored.
Are there any ways to solve this issue that I am missing?
One way to workaround such a clash is to build your MaterializeCSS to include only the parts you so need for your project.
For instance, if you do not need the buttons styling of MaterializeCSS, you could simply, via sass, compile the materialize.scss and cherry pick buttons out of the file.
If going down the path of building your custom .css of Materialize is a long short for you, you can try using materialize.khophi.co (Disclaimer: I built it).
Find more about how to customize your MaterializeCSS: http://materializecss.com/getting-started.html
I know it's usually suggested not to duplicate code, and you want to try steering away from overrides, but would it be possible to find the section of css you like (i.e. select box from materialize) and copy that in to a new custom css file, renaming the selector so you can use it seperately from Materialize/Kendo UI?
You can manually edit the stylesheet of eighter party. Take the non-minified CSS, and prepend every base path with a short prefix:
.card {
....
}
becomes
.mat.card {
....
}
That way, for every materialize style, you use .mat before anything. Or, if you mainly use materialize, do the same thing for Kendo UI.
This is a lot of pain, but would solve your issue.

Qt-Creator: How to set a application wide style sheet that can be seen in QTDesigner?

With
void QApplication::setStyleSheet()
I can set a global style sheet for my Qt application.
For example, I set the default background of all QWidgets to black.
However, in the QT Designer all my widgets still have the default looks (grey background), because it doesn't know anything about my code.
Is there a way to set a global style sheet to my application that also affects the widgets looks in the QT Designer? Then I wouldn't have to compile my project every time I want to see how it looks.
Or is there maybe a more sophisticated way to solve this problem?
There is solution. You can set in Qt Designer your stylesheet for top level widget styleSheet property.
For example: you set style
QWidget {background-color:black;}
for MainWindow form in Qt Designer and all child widgets now have black background.
In the Preferences dialog (menu: Settings, Preferences...), there's a section in Forms called "Print/Preview Configuration". You can set a stylesheet there for the preview action (normally on Ctrl+R). This won't change the colour of the form as you edit it, but you can quickly see it as it will appear in your application.
See also my question Can I style the top-level form in Designer preview?
As you said yourself: It doesn't know anything about your code. So nothing you can do in code. But compiling your project every time you want to see how it looks? One stupid question... don't you know about the preview function in the designer? Press ctrl-alt-r.
Of course, it shows only the style, which is applied to the widget currently loaded in the designer. But you could temporarily set your style sheet to this widget to see how it would look, if you later on set this sheet globally in your program. Not perfect, but at least no need to compile your whole project.

Flex 4 skins -- when to include Actionscript Styling Code?

When using Flash Builder to create a new component Skin based on an existing Skin, one has the option to include Actionscript styling code or not. Wouldn't this code always be necessary?
Here is an example of two people, both of whom have skinned the spark Panel.
With styling code:
http://blog.flexexamples.com/2009/10/19/repositioning-the-control-bar-on-a-spark-panel-container-in-flex-4/
Without styling code:
http://www.popamihai.com/2010/11/flex/skinning-flex-4-components-skinning-the-spark-panel-component/
But they both seem to run fine. How can this be?
The styling code still gets applied due to the fact that you're extending a class.
You should add the styling code when you intend to change it.

Qt stylesheet used in Qt Creator, AutoCAD,

Is there a stylesheet available for use in Qt applications (through Qt Creator) that makes your GUI use the stylesheet you see in Qt Creator itself, as well as in AutoCAD and some other applications?
What is the name of that stylesheet or where can I get it? It looks much like the Vista stylesheet though...
And whenever you set a custom stylesheet to your Qt application, will it display the same style on all platforms, or will it still display native GUI parts?
To the people that may want to find out more: The style seems to be called manhattanstyle and extends QWindowsStyle. It is not a css-stylesheet and therefore not just copy and paste to set up. It seems to have some other dependencies in the source code, so I don't know how much it will take to adapt it.
The source is found in the [qt-creator source code]/src/plugins/coreplugin/manhattanstyle.cpp
And btw: if you are running debian/ubuntu: type apt-get source qt-creator to get the source ;)
I can't say as to how you would get style sheets that match Qt Creator or AutoCAD but to answer your other question: When you apply a style sheet, it applies to the object you applied it to, and the child hierarchy of that object. Any widget not addressed by the style sheet in some way will maintain the native look and feel that matches the Style (not style sheet) chosen by Qt as most appropriate for you application based on the user's platform and desktop environment.
yes, somebody has separated it out.
see this Manhattan style

Resources