Qt stylesheet used in Qt Creator, AutoCAD, - qt

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

Related

How to use .ui.qml files from Qt creator version 6

I've been some reading/watching some tutorials here and there about qt quick and qml from last few days. But the user interface of qt creator, the boilerplate that it produces on a new qt quick project in each of the tutorial had been different. there's so much confusion.
I want to make a simple Hello World Qt Quick project, I followed this book from packt. (It has changed from the last time I saw it, but still doesn't work)
I added some a UI file, which added *.ui.qml and *form.qml files. Now if I edit .ui.qml in design, No change is reflected on any other file, but if I open some other file in design, it prompts me to use the .ui.qml file instead. The examples give an error "No Cmake config found". I'm using Qt6.2 on Arch/wayland, downloaded via installer.
How is it supposed to work? I have read this answer, and few others but I'm still confused.
Could you link to a proper tutorial, or a simple example?
The best way to think about it is that *.ui.qml should be used for UI elements and their settings. They should be about the structure, layout and styling of your UI. Doing that also happens to make the files presentable and editable in Creator's Design Mode since it simplifies the structure of the QML to the point where it can reliable present it and modify it.
*.qml files on the other shouldn't have UI elements and should instead primarily contain functions, properties and signal handers.
This pattern is sometimes referred to as "code behind". It sort of follows the same philosophy with HTML and CSS. Modern HTML documents primarily represent the structure of a page while CSS is placed in separate files to govern how they should be styled.
In this case *.ui.qml files contain the structure and styling while *.qml files containing the behavior. Creator will create a pair of them while adding a QML UI resource to your project where the .qml file inherits from the .ui.qml file.
Other than this inheritance and to encourage the code behind pattern, there's no real difference between a .qml and .ui.qml file. Creator will also try to steer you to the .ui.qml version of the pair when you go into designer to help encourage this pattern.
I will note that Qt violates this pattern a bunch all over their documentation and examples....

Qt Virtual Keyboard Custom Style

I need to build a custom Style for a Qt VirtualKeyboard on a small screen to maximize its readability. I have built a custom layout into my project, and using the QT_VIRTUALKEYBOARD_LAYOUT_PATH it works great.
The problem I am having is that the documentation states that the custom style must be placed in the Qt Directory. I need this style to be portable, however, so storing this newly built style on my local machine, rather than in the project itself, will not be acceptable.
Is there any way to build a use a keyboard style within a project?
It doesn't have to be in the Qt directory, just in a directory that is under QtQuick/VirtualKeyboard/Styles/ and in the QML import path.
As an example, take a look at the auto test:
http://code.qt.io/cgit/qt/qtvirtualkeyboard.git/tree/tests/auto/styles/data
You can also put the style in a .qrc file under that folder structure:
http://code.qt.io/cgit/qt/qtvirtualkeyboard.git/tree/src/virtualkeyboard/virtualkeyboardsettings.cpp#n70
I've created a task to make this clearer: https://bugreports.qt.io/browse/QTBUG-66172

Load an external stylesheet in QT from another external stylesheet

I'm new to QT and I'm trying to see if it's possible to load an external stylesheet from a global stylesheet just like in web dev, something like using the syntax "link rel="stylesheet".
Right now we have a global CSS sheet that is being called via C++ code with all the global elements and specific widget modifications, it has 2k lines of code and it's becoming unmanageable. I know I can keep the global file and start adding resource stylesheets or pure code put directly into QT Creator Style Sheet editor for each widget. However, the head of development really wants to separate that my code from his team, so avoid any changes in QT UI file as much as possible, so if something breaks he will know when it was me or him.
Is this possible? can I call a stylesheet from a stylesheet? I couldn't find this syntax in the QT guide.

How to create a QT plugin that customizes UI?

We would want the users to be able to optionally customize our QT applications. So if they would want to create their own theme for our applications, all they have to do is load their own CSS file.
Do we really need to create a plugin to be able to do that? If yes, could somebody give me the basic steps/ or a jump start on how to do it? If no, are there features in QT that I need to know to be able to do that without creating a plugin?
I have a Jabber instant messenger which is plugin based and written in Qt. It includes a style plugin that does exactly what you describe. The source for that plugin is here:
https://github.com/sje397/saje/tree/master/plugins/styles/
(Note: this is a plugin for my application - not a 'Qt style plugin')
Basically all you need to do is load a style sheet and call QApplication::setStyleSheet:
QFile f("filename");
if(f.open(QIODevice::ReadOnly)) {
qApp->setStyleSheet(f.readAll());
}
An example of a valid style sheet is here. Note that it is for my app, so includes some of my own class names etc.

Styling only promoted widgets using QT Creator

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

Resources