[Development] so it turns out there *is* a way to get Qt5 apps to use a custom style automatically?

René J. V. Bertin rjvbertin at gmail.com
Sat Sep 5 15:39:27 CEST 2015

Thiago Macieira wrote:

This seems more appropriate for the Development ML so I'm taking it there.

> On Friday 04 September 2015 12:19:24 René J.V. Bertin wrote:
>> A bit of testing confirms that QT_PLUGIN_PATH is involved, but on my OS X
>> machine the style plugin is already in the plugin path, so something else
>> must be required to make it the default style.
> It's another type of plugin called "platformthemes". It's provided
> specifically for platforms that are written with Qt because of a dependency
> reversal: Qt itself cannot integrate with it from inside the platform plugin
> as it hasn't been built yet.

It turns out to be straightforward to include qgenericunixthemes.cpp in an OS X 
build, and to invoke it:

QPlatformTheme *QCocoaIntegration::createPlatformTheme(const QString &name) 
    qDebug() << "QCocoaIntegration::createPlatformTheme(" << name << ")";
    if (name == QLatin1String(QCocoaTheme::name)) {
        qDebug() << "returning the QCocoaTheme";
        return new QCocoaTheme;
    // createUnixTheme() is patched to return NULL as the fallback case on OS X
    QPlatformTheme *unixTheme = QGenericUnixTheme::createUnixTheme(name);
    if (unixTheme) {
        qDebug() << "returning" << unixTheme;
        return unixTheme;
    else {
        qDebug() << "returning QPlatformIntegration::createPlatformTheme(" << 
name << ")";
        return QPlatformIntegration::createPlatformTheme(name);

and I can indeed use `foo --style=kde` to start foo using the currently selected 
style for KDE applications. However:

1- simply setting KDEHOME to ~/.kde doesn't have any effect (it's not required 
for --style=kde to work either)
2- apparently, QCocoaIntegration::createPlatformTheme() is always called with 

I'll be looking at the call stack to see how 
QCocoaIntegration::createPlatformTheme() and 
QXcbIntegration::createPlatformTheme() get called, but would appreciate 

For the record: I think Qt loads the KDE style on Linux in order for pure Qt 
apps to integrate nicely with KDE (KF5) apps. It'd be nice if this were possible 
(optional, user choice) on OS X too (as is the case with Qt4/KDE4 apps) once KF5 
becomes operational. 


More information about the Development mailing list