Offscreen QPA: Use fusion style always

Prevent it from crashing when naively using it for example
on Windows, which defaults to the Windows Vista style operating
on native window handles.

Change-Id: I7b1dfb00a6b6860d0f0a134653ce1142b45959ec
Reviewed-by: Sami Nurmenniemi <sami.nurmenniemi@qt.io>
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
bb10
Friedemann Kleint 2017-11-13 11:28:41 +01:00
parent e4206c3cd5
commit c84f755489
2 changed files with 35 additions and 0 deletions

View File

@ -61,6 +61,7 @@
#include <QtGui/private/qguiapplication_p.h>
#include <qpa/qplatforminputcontextfactory_p.h>
#include <qpa/qplatforminputcontext.h>
#include <qpa/qplatformtheme.h>
#include <qpa/qplatformservices.h>
@ -167,6 +168,37 @@ QAbstractEventDispatcher *QOffscreenIntegration::createEventDispatcher() const
#endif
}
static QString themeName() { return QStringLiteral("offscreen"); }
QStringList QOffscreenIntegration::themeNames() const
{
return QStringList(themeName());
}
// Restrict the styles to "fusion" to prevent native styles requiring native
// window handles (eg Windows Vista style) from being used.
class OffscreenTheme : public QPlatformTheme
{
public:
OffscreenTheme() {}
QVariant themeHint(ThemeHint h) const override
{
switch (h) {
case StyleNames:
return QVariant(QStringList(QStringLiteral("fusion")));
default:
break;
}
return QPlatformTheme::themeHint(h);
}
};
QPlatformTheme *QOffscreenIntegration::createPlatformTheme(const QString &name) const
{
return name == themeName() ? new OffscreenTheme() : nullptr;
}
QPlatformFontDatabase *QOffscreenIntegration::fontDatabase() const
{
return m_fontDatabase.data();

View File

@ -69,6 +69,9 @@ public:
QPlatformFontDatabase *fontDatabase() const Q_DECL_OVERRIDE;
QAbstractEventDispatcher *createEventDispatcher() const Q_DECL_OVERRIDE;
QStringList themeNames() const;
QPlatformTheme *createPlatformTheme(const QString &name) const;
static QOffscreenIntegration *createOffscreenIntegration();
private: