Problems with QML Style change from Qt5 to Qt6
-
I am upgrading a Qt5 app to Qt6. Everything is fine, except for the fact that the styles are weird and off.
This is how it used to look:
This is how it looks now:
Button text placements are wrong, the background color has changed, I'm getting a ton of
The current style does not support customization of this control
warning messages, etc...Before I manhandle this back into shape, is there a simple Style setting I'm overlooking in moving from Qt5 to Qt6? I've tried a variety of
import QtQuick.Controls...
, andimport QtQuick.Controls.Basic 2.15
gives the most similar results, although the colors are still inverted and button sizes still are subtly adjusted. -
@Kenz-Dale That happens because you didn't specify an explicit Style for your app.
In Qt 5 the default style was the aptly named Default Style. In Qt 6, it's platform dependent. So if you are on macOs, it will be the macOs Style.
You can specify the style to be the Basic Style. If you want to use compile time selection and not runtime selection, make sure you don't
import QtQuick.Controls
but onlyimport QtQuick.Controls.Basic
. -
@GrecKo Thanks, that helped a ton.
Adding#include <QQuickStyle> . . . int main(int argc, char *argv[]) { . . . // Set QML style. Could be Material, Universal, Basic, etc... Doing // it here sets it app-wide. QQuickStyle::setStyle("Basic"); . . . }
was exactly what I needed.
-