Solved Qt 5.7: Material.accent not working
-
Hi; My basic code is here:
ApplicationWindow { visible: true width: 300 height: 300 title: qsTr("Hello World") Material.theme: Material.Dark Material.accent: Material.Purple header: ToolBar { id: toolBar Material.accent: Material.Amber RowLayout { anchors.fill: parent ToolButton { text: qsTr("\u25C0 %1").arg(Qt.application.name) } } } }
When I ran this app, I see ToolBar color is blue:
I triedMaterial.accent: Material.color(Material.Amber)
andMaterial.background: Material.Amber
but not working, always toolbar color is blue. How can I set it? Thanks. -
@Ibrahim in qml you have imported QtQuick.Controls.Material 2.0 ?
and you have configured Material style ? per ex in main.cpp:
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
qputenv("QT_QUICK_CONTROLS_STYLE", "material"); -
@ekkescorner thanks. Yes, I imported
QtQuick.Controls.Material 2.0
and I setQGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); qputenv("QT_QUICK_CONTROLS_STYLE", "material");
in main.cpp.
But it's not working withMaterial.accent
. I triedMaterial.primary: Material.Amber
and it's working well.
Actually I don't understand, what is difference betweenMaterial.accent
andMaterial.primary
andMaterial.background
? -
@Ibrahim you should study https://material.google.com/style/color.html# to see where accent is used and where primary is used
and the Material.background is normaly set by Qt Quick Controls 2 and depends from Theme.
you can overwrite the background - see here: https://doc-snapshots.qt.io/qt5-5.8/qtquickcontrols2-material.html#material-background-attached-prop