How to obtain entire Qt StyleSheet for QMacStyle - qt

Is it possible to obtain a text file of the entire Qt5 StyleSheet for QMacStyle (or its equivalent QProxyStyle that's apparently used in Qt5)?
I'm hoping to get a list of all the property:value pairs ('background-color', 'border-radius', 'margin-top', 'padding', etc.), along with their default settings, that are used for each of the common widgets (QPushButton, QTabBar, etc.).
Qt5 on Mac OSX looks great due to all of the native-looking widgets (see e.g. Macintosh Style Widget Gallery). I'd like to perform some surgical replacements of a number of style properties in my application, but otherwise keep the native look-and-feel. (An alternate take on the problem, or at least on the same end goal, is represented in my related question How to override just one property:value pair in Qt StyleSheet.)
If I knew the entire Qt StyleSheet equivalent for a QTabBar or QPushButton, I could reconstruct the native look-and-feel in my own invocations of widget->setStyleSheet(), adding in my few necessary tweaks.
I've searched the entire Qt5.4.0 directory hoping to find a *.qss file representing OSX style, but to no avail (I found the promisingly named examples/widgets/widgets/stylesheet/qss/default.qss, however all it says inside is //* empty stylesheet *//). I've exhausted my ideas running grep on the full Qt5 source directory, including in qt-everywhere-enterprise-src-5.4.0/qtbase/src/widgets/styles/, which may indeed contain the details but not in very digestible form).
Thanks --

QMacStyle is a QStyle subclass that is using Apple's HITheme for drawing (look for the files qmacstyle_mac* to see the implementation), so there is no stylesheet to obtain.

Related

atom editor: list of `styles.less` options

Where can I find a list of the keywords for the styles.less configuration file for Atom?
There are many specific requests for highlighting one thing or another, but I cannot seem to find a general overview of the implemented keywords.
The scope names are supposed to be based on the ones listed at the bottom of the this page (the sublime text ones are also based off this list)
https://manual.macromates.com/en/language_grammars
In practice, nothing fits perfectly. The most reliable way to get the needed scope is running Editor:Log cursor scope in the command palette, which will make a notification popup with a list of all the scopes at the cursor. You then need to pick the relevant ones, and prepend each segment with syntax--.
E.g., if the scope popup says source.md, markup.bold.md, you can target bold scopes with
atom-text-editor .syntax--markup.syntax--bold {
color: red
}
And that's just for text; anything at all can be modified if you know enough CSS. Opening dev tools lets you use the selector tool to find anything you like in on the page the DOM. Targeting it in the styles.less file will let you apply changes.
Here is the namespace for Sublime:
https://www.sublimetext.com/docs/3/scope_naming.html

Can I globally switch to native text rendering in Qt Quick Controls 2?

I would like to use native rendering for all the text in my application. For each Text, Label, etc. element I can do this
Text {
renderType: Text.NativeRendering
}
to trigger native rendering. I can also use the software renderer for the whole application:
QQuickWindow::setSceneGraphBackend(QSGRendererInterface::Software);
However due to some bugs with the software renderer and some performance issues, I would like to avoid that.
Is there a global switch to change the render type?
Since Qt 5.7, you can change the default Qt Quick text render type, but unfortunately only at build time. In order to change the default, you would have to rebuild libQt5Quick.so with QT_QUICK_DEFAULT_TEXT_RENDER_TYPE set to NativeRendering. For more details, see https://codereview.qt-project.org/#/c/121748/ .
If you have installed Qt using an installer from qt.io, install the source packages using the maintenance tool if you already haven't done so, navigate to qtdeclarative/src/quick, run qmake with the define, and build. Something along the lines:
cd path/to/Qt/Sources/5.8/qtdeclarative/src/quick
# NOTE: make sure to run qmake from the same/correct Qt installation
path/to/Qt/5.8/<spec>/qmake "DEFINES+=QT_QUICK_DEFAULT_TEXT_RENDER_TYPE=NativeRendering"
make -jN
If you have a self-built Qt installation, invoke make clean (or if you want to save time, just delete qquicktext*.o) before make to rebuild the library.
EDIT: Since Qt 5.10, it is also possible to specify the default text render type in C++ via QQuickWindow::setTextRenderType(). Just notice to set it before loading the QML content.
The environment variable QML_DISABLE_DISTANCEFIELD controls this.
If you put
qputenv("QML_DISABLE_DISTANCEFIELD", "1");
at the beginning of your main, you will get a nice and sharp text rendering everywhere.
Source: http://www.kdab.com/~thomas/stuff/distancefield.html
Add this line first in c++ main function : QCoreApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);

Virtual Keyboard qt how to put it in azerty

I want to change the VirtualKeyboard to [azerty].
I tried to put VirtualKeyboardSettings.locale = "fr_FR" but it doesn't work.
I also tried to put CONFIG += lang-fr_FR in the .pro file like it says in the Qt documentation but still doesn't work.
I'm not sure what platform you are targeting, however Qt typically picks up on the runtime platform's locale setting, and applies this automatically wherever localisation is required, e.g. controls, dates, times, numbers etc. I would expect this to include the virtual keyboard.
However, if necessary you should be able to override the locale application-wide using QLocale::setDefault. See the documentation here.
If this doesn't work, please add some more information to your question so we can get a better idea of the problem.

How do "theme" icons work in Qt Creator Designer?

When I create the "Command link button" (QCommandLinkButton) it has relatively nice green arrow icon.
I would like to see what other nice icons can I choose. When I try to change the icon, [Theme] appears instead of path or some GUI selection dialog:
I also noticed the context menu:
When I click Set icon from theme, again expecting some GUI selection list, I get just a text field:
What I was imagining:
Where's the list of icons from which the green arrow was taken?
QIcon::fromTheme works under specific conditions.
If it can find it in the QIcon::themeSearchPaths() for the QIcon::themeName()
If the desired icon isn't there, Qt Designer won't be able to do any of the from theme, named icons.
But... if you check your target system for the theme search paths and set the theme name, you are more likely to have success.
Example
On linux, I wanted to get a plus and a minus icon.
I found list-add.png and list-remove.png fit the bill.
https://github.com/GNOME/adwaita-icon-theme/tree/master/Adwaita/16x16/actions
http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
I did a locate on my system and found these:
/usr/share/icons/gnome/16x16/actions/list-add.png
...
/usr/share/icons/gnome/32x32/actions/list-add.png
/usr/share/icons/gnome/scalable/actions/list-add.svg
/usr/share/icons/oxygen/16x16/actions/list-add.png
...
Forcing with fallback icon in QIcon::fromTheme
Find the icon on the filesystem:
ui->toolButton->setIcon(QIcon::fromTheme("list-add",
QIcon("/usr/share/icons/gnome/16x16/actions/list-add.png")));
Find the icon in the qt resource system...
Add the icon in a qrc file in your build, then reference it's path.
ui->toolButton->setIcon(QIcon::fromTheme("list-add",
QIcon(":/list-add.png")));
Overriding the current icon theme
qDebug() << "themeSearchPaths:" << QIcon::themeSearchPaths() << QIcon::themeName();
// themeSearchPaths: ("/usr/local/share/icons", "/usr/share/icons", ":/icons") "hicolor"
The default theme for the system, and for the target deployment machine, likely didn't have the icons in it I wanted... but the gnome or oxygen icon desktop theme installed would almost always have it...
QIcon::setThemeName("oxygen");
Note that you won't see the preview in Qt Designer necessarily because it doesn't set the theme until runtime of your code.
The gnome icon library has 1100+ icons in it. Here is one list:
https://gist.github.com/peteristhegreat/c0ca6e1a57e5d4b9cd0bb1d7b3be1d6a
This works as long as you know what themes are available on the target system.
The list from freedesktop.org has 286 icons listed.
Use icons included in Qt
Just like #peppe pointed out, Qt includes 70 standard icons, too.
widget->setIcon(widget->style()->standardIcon(QStyle::SP_BrowserReload));
http://doc.qt.io/qt-5/qstyle.html#StandardPixmap-enum
Conclusion
Using a stock library on your target system is probably the fastest. Using the Qt built-ins is fast to figure out and use, but is fairly limited. Using a resource file is probably the most robust method, and gives unlimited options on what icon to use.
Be sure to pick a standard icon pack, and think about licensing and attributions, and some other things like that.
And there is no shortage of icons available online:
https://www.quora.com/What-is-the-best-icon-library
https://www.google.com/search?q=open+source+icon+library
Hope that helps.
I don't think that's the function you want to use. The "theme" name there corresponds to the QIcon::fromTheme functionality, which uses icons named according to the FDO specification
http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
And they're not really supported on non-FDO platforms (Windows, Mac, ...) unless you deploy your own theme files.
Now some stock icons are shipped with Qt itself; I don't know how to set them from Designer, but from code you can use QStyle::standardIcon:
widget->setIcon(widget->style()->standardIcon(QStyle::SP_BrowserReload));
If the icon you need is not provided by Qt, you'll need to ship it. In that case the Resource System is a convenient way to bundle it alongside your executable.
Last, but not least, from a UX point of view you should consider using QToolButtons unless you're really building a Vista-like wizard.

Show standard warning icon in Qt4

I'm trying to display a "warning" icon next to a QLineEdit if it contains invalid data. I was trying to use QStyle::standardIcon(QStyle::SP_MessageBoxWarning) to get a standard pixmap and place it inside a QLabel, and in some cases this seems to work. When running Gnome the icon is displayed correctly, but when running under KDE no icon is shown. I assume that the warning icon is simply not included in the style used under KDE.
What is the preferred way to display a "standard" warning icon in Qt? Does there exist some list which shows which icons are included in every style? How can I get an icon from a style that I know includes the warning icon?
The last time I had a similar problem, I found this Qt labs discussion useful. It informed me that QIcon now (since 4.6 I believe) has a QIcon::fromTheme function that allows you to load an icon based on the Freedesktop.org Icon Naming Specification, and in addition provide a fallback icon to be used if the current theme does not have the icon in question.
What I did was then to include some very basic icons for use as fallback, and in general specify icons only by their Freedesktop names. This gave a theme-consistent look almost always, and the program still worked in cases where people were missing icons.
As for the warning icon, I'm guessing/hoping that every theme must have the one named "dialog-warning", and that it's what you're looking for.
I hope this helps.
Edit: Oh and, in case you don't know, it can be useful to look at for example the Tango icon set to get a rough idea of what the Freedesktop names correspond to (although it is of course theme-dependent).
Qt does bundle a number of images that are resources that you can use in your own code. These images are a superset of those available via standardIcon() You may want to verify that the particular image is included in the versions of Qt you're targeting.
The end result could look like the following:
QPixmap pixmap(":/trolltech/styles/commonstyle/images/up-128.png");
// use pixmap as needed
For anyone who wants to know how to do this in a Windows environment you can:
Create a qLabel in your custom class, and then in the constructor of that class create a QIcon with the style you want, convert it into a pixmap and use the QLabel::setPixmap() function to apply it to the one you created:
QIcon icon = style()->standardIcon(QStyle::SP_MessageBoxWarning); //or
//whatever icon you choose
QPixmap pixmap = icon.pixmap(QSize(60, 60));
ui->iconLabel->setPixmap(pixmap);
ui->iconLabel->setScaledContents(true); //you can set this to fill the
//dimensions of your qLabel if you wish.

Resources