Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTK and Native styles not available #306

Open
Fornax96 opened this issue May 2, 2017 · 12 comments
Open

GTK and Native styles not available #306

Fornax96 opened this issue May 2, 2017 · 12 comments

Comments

@Fornax96
Copy link

Fornax96 commented May 2, 2017

I noticed that applications built with these bindings use Fusion style by default instead of the native style, so I was trying to set it to GTK manually with this line of code: widgets.QApplication_SetStyle2("GTK"). But when I execute it it only prints this message to stdout: QApplication: invalid style override passed, ignoring it.. When I print the available styles it only shows Windows and Fusion.

I am using Go 1.8.1 and Qt 5.8 on Linux Mint 18 Cinnamon with the Mint-Y-Dark theme.

In my Qt install directory I can see that libqgtk3.so is present in plugins/platformthemes. When I run my application with QT_DEBUG_PLUGINS=1 it also shows that the library is being loaded:

QFactoryLoader::QFactoryLoader() checking directory path "/home/wim/Programs/qt/5.8/gcc_64/plugins/platformthemes" ...
QFactoryLoader::QFactoryLoader() looking at "/home/wim/Programs/qt/5.8/gcc_64/plugins/platformthemes/libqgtk3.so"
Found metadata in lib /home/wim/Programs/qt/5.8/gcc_64/plugins/platformthemes/libqgtk3.so, metadata=
{
    "IID": "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1",
    "MetaData": {
        "Keys": [
            "gtk3"
        ]
    },
    "className": "QGtk3ThemePlugin",
    "debug": false,
    "version": 329728
}


Got keys from plugin meta data ("gtk3")
QFactoryLoader::QFactoryLoader() checking directory path "/home/wim/Documents/Workspace/go/src/fornax96.me/qt_test/deploy/linux/platformthemes" ...
loaded library "/home/wim/Programs/qt/5.8/gcc_64/plugins/platformthemes/libqgtk3.so"

Even when running the application with -style GTK it still uses Fusion.

Is there any way to make it use the native platform style?

@therecipe
Copy link
Owner

Hey

Yeah, if IIRC then there were some problems in Qt 5.6.x and 5.7.x because of the change from gtk2 to gtk3 or something. And therefore the libqgtk3.so wasn't available for these version at all.

But since you are on 5.8 and you also have found thelibqgtk3.so, things should work ...

It could be that qtdeploy is not correctly bundling the plugin though. Could you try to use go run and go build to build your project, and then see if that makes a change? Or if you already used go ..., maybe try to use qtdeploy instead?

However, I will look into that tomorrow and try to reproduce it.

Is there any way to make it use the native platform style?

Did you already tried to set the QT_QPA_PLATFORMTHEME env variable?

Here are some related infos (some may be for some other distros)

manjaro/release-plan#73
https://forum.qt.io/topic/78023/qt-applications-don-t-look-natie-linux-mint-18-1-cinnamon
https://forum.qt.io/topic/75080/use-gtk-theme-on-linux/9
https://bugreports.qt.io/browse/QTBUG-52259

@Fornax96
Copy link
Author

Fornax96 commented May 3, 2017

Thanks for the reply!

Another thing I noticed is that when I don't try to set the style at all (no QApplication.SetStyle and no -style param), it still shows the message QApplication: invalid style override passed, ignoring it., like the gtk plugin is also trying to set it.

I tried go run and go build, but nothing changed in respect to qtdeploy build desktop.

export QT_QPA_PLATFORMTHEME=GTK also didn't help.

This function: widgets.QStyleFactory_Keys() still prints only this: [Windows Fusion]. Setting it to Windows style works, but it looks terrible.

EDIT: The invalid style override passed message is because Mint sets QT_STYLE_OVERRIDE=gtk by default. If I set it to blank it doesn't print the message, but it still uses Fusion style. Setting the var to Windows also works as expected.

@therecipe
Copy link
Owner

Okay, looked into it on Mint 18.1 Cinnamon, but I couldn't find a solution.

Like you, I always only get [Windows Fusion] for the available styles.
And changing the style to something else always only results in the QApplication: invalid style override passed, ignoring it. error.

But it seems like this is not an issue that is limited to Mint, but it rather affects a range of distros.
And they all seems to work around this with different solutions: qt5ct on Arch/Fedora or qt5-style-plugins on Ubuntu/Debian for example. But these solutions seem to only work if you also use the system Qt libs and not the official "portable" Qt libs.

I also read somewhere, that the libqgtk3 plugin is probably not in charge of the actual style, but it is only used to get some general desktop environment infos. (But I don't know if that's true or not)

However, it seems like there is not much that I can do at this point.
The only options I see here would be that you may need to use the official Qt 5.6.2 libs (which should style correctly from what I read), or maybe hope this style issue is fixed in Qt 5.9 (which should be released next month).

@Fornax96
Copy link
Author

Fornax96 commented May 4, 2017

It makes sense that the Distro maintainers have patched the Qt libs to properly support GTK styling, because all applications in the repositories also use the Qt libs from the repositories. Is there no way for Go Qt to also use the native libs? It's kind of frowned upon for package maintainers to ship custom versions of libs that are already in the repositories. The deb linter even gives a warning when installing a package that ships vendored Qt libs (last time I tried it, at least).

I'll try Qt 5.6.2 when I find the time. I hope this will be fixed in 5.9, or I may have to stick to 5.6.2 forever (until it's fixed at least).

There also this other Qt binding: https://github.com/visualfc/goqt. It's pretty outdated and lacks a lot of features, but it does properly apply the GTK style without workarounds, maybe you can get some inspiration from there :). He's taking a different approach though, he wrote his own SO library that interfaces between Go and the system Qt libs.

@therecipe
Copy link
Owner

Is there no way for Go Qt to also use the native libs?

You can use your system package managers Qt libs by exporting export QT_PKG_CONFIG=true.
To make this work you probably also need to install the Qt docs "qt5-doc*" and some additional packages beside the main Qt dev "qt5base-dev" package, such as "libqt5svg5-dev" and "qtdeclarative5-dev". (I suspect that "visualfc/goqt" uses the system Qt libs by default and the styling therefore works)

However, I tried to get it working on Mint 18.1 with the system Qt libs, but it didn't worked out because they still only provide Qt 5.5.x libs and the binding is only backward compatible with Qt version >= 5.6.x.

I also tried it with the Qt 5.8.x libs from beineri/opt-qt58-xenial, but they didn't properly style the widgets as well.

@Fornax96
Copy link
Author

Fornax96 commented Jul 19, 2017

You can use your system package managers Qt libs by exporting export QT_PKG_CONFIG=true.

Awesome.

After trying Qt 5.9.1 and coming to the conclusion that it's still broken I decided to try the native libs.

Then I installed a few dozen Qt libs, because the setup script kept throwing errors (save your time, just install all of them "qt5-*"). And it works!
image

This also works with my own application when running go run main.go and go build main.go. It supports all styles that qt5ct supports: [bb10dark bb10bright cleanlooks gtk2 cde motif plastique qt5ct-style Windows Fusion].

But when I compile it with qtdeploy build desktop . it still only supports [Windows Fusion], and uses fusion by default.

Next thing to test is how portable it is, won't be very useful if it only runs on my PC, which I'm kind of afraid of.

EDIT:

However, I tried to get it working on Mint 18.1 with the system Qt libs, but it didn't worked out because they still only provide Qt 5.5.x libs and the binding is only backward compatible with Qt version >= 5.6.x.

Of course. I'm running Arch at home, which is always more up-to-date than most debian distros. It ships with Qt 5.9.1 currently. So I guess this (my compiled binary) will only work on systems with Qt 5.9.1 then. Still I'll try some more stuff.

@therecipe
Copy link
Owner

therecipe commented Jul 20, 2017

But when I compile it with qtdeploy build desktop . it still only supports [Windows Fusion], and uses fusion by default.

Mh, then you probably need to start the binary directly if you use QT_PKG_CONFIG, not like usual with the *.sh. Or maybe try to remove the line containing LD_LIBRARY_PATH (or some of the others that start with "export") in the *.sh.

Of course. I'm running Arch at home, which is always more up-to-date than most debian distros. It ships with Qt 5.9.1 currently. So I guess this (my compiled binary) will only work on systems with Qt 5.9.1 then. Still I'll try some more stuff.

Yeah, QT_PKG_CONFIG is intended to be used if you want to create applications for your package manager. So your applications will work on all the other Arch systems with Qt 5.9.1, but not on some other distro. If you want a portable application, then you need to use the official Qt version with the broken styling :( Or the old 5.6.2 version, where the styling still works.

@RadhiFadlillah
Copy link
Contributor

RadhiFadlillah commented Aug 5, 2017

Hey @therecipe @Fornax96, it seems Qt already abandoned development of GTK style binding for Qt. Even in latest documentation for QApplication::setStyle, GTK is not mentioned as one of available style :

The string must be one of the QStyleFactory::keys(), typically one of "windows", "fusion", "windowsxp", or "macintosh". Style names are case insensitive.

@therecipe
Copy link
Owner

@RadhiFadlillah Thanks for the info :)

It's probably to time consuming to get it working on all the different distros ...

@Fornax96
Copy link
Author

Fornax96 commented Aug 7, 2017

That commit is for the GTK3 plugin. GTK2 is currently still supported, but the GTK developers are phasing it out in favor of GTK3, which has been declared stable for a while now.

If they really plan to abandon the GTK style plugin that will probably break a whole lot of apps. I already have dozens of Qt apps on my PC that use GTK style (VLC, Zim, KeePassX, etc).

I think it's very likely that the plugin will continue to be maintained by the community because it's required to make the gnome desktop (and derivatives) look consistent. Without it the Qt apps look awkward and out of place on most Linux-based operating systems.

I know that Qt is the native GUI toolkit for KDE, I wonder how they handle styling.

In the end it's probably easier to implement your own dark and light themes and make it configurable, than to rely on style plugins. Probably what I will be doing.

@RadhiFadlillah
Copy link
Contributor

@Fornax96 have you tried deploying using docker image ?

I am using Go 1.8.3 on Manjaro Linux with Arc theme. When I try to deploy my app using locally installed Qt (qtdeploy build linux), it give me an app with fusion style :

Fusion style only

But when I deploy my app using docker image (qtdeploy -docker linux) it give me an app with native GTK style :

Native GTK style in GIF

@Fornax96
Copy link
Author

Fornax96 commented Aug 8, 2017

To be honest, I have no idea how docker works or how to use it. I thought it was kind of like virtutalbox.

I've been doing tons of research, reading through mailing lists and browsing through repositories. Eventually I found out that gtk2 style has been deprecated from Qt Base and was moved to qtstyleplugins for compatibility: https://github.com/qt/qtstyleplugins/tree/master/src/plugins/styles/gtk2.

In Qt Base gtk2 style has been replaced by gtk3 style in 5.7, which can be found in the repository: https://github.com/qt/qtbase/tree/5.7/src/plugins/platformthemes/gtk3. This is great, it means that gtk3 style should be natively supported from 5.7 and up.

The bad news is that most stable (debian-based) distros are stuck on 5.5.X, where gtk2 has been moved to qtstyleplugins and gtk3 has not been implemented yet, so there's no way to support native styles.

I guess all we can do is wait until the repository maintainers have caught up.

EDIT: Ugh, apparently in Qt a "style" is completely different than a "theme". A theme is just the icons, fonts and cursors in the application, while the style paints the widgets and such. This means the gtk style is not supported in 5.7 and up :( My guess is that this is why the stable distros are not updating their Qt installations. And I guess distros that do support it enable the plugin themselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants