[solved] QML, Toolbar backgroud depending on WIndows or Android
-
Hi,
i have a toolbar in my QML code like below. The style :ToolbarStyle should only valid for Android, not for Desktop. How can i do that?
ThxtoolBar: ToolBar { id: mainToolBar width: parent.width style: ToolBarStyle { background: Rectangle { width: parent.width height: parent.heigt color: "#fcdb00" } } RowLayout { anchors.fill: parent spacing: 0 ToolButton { action: newsetupAction } ToolButton { action: opensetupAction } ToolBarSeparator {} ToolButton { action: savesetupAction } ToolButton { action: savesetupasAction } Item { Layout.fillWidth: true } } }
-
@HappyCoder Since
style
requires aComponent
you can encapsulate inToolBarStyle
and assign it tostyle
. The you can add a condition forstyle
to loadComponent
as per platform. Eg:style: Qt.platform.os==="android" ? androidComponent : desktopComponent Component { id: androidComponent ToolBarStyle { background: Rectangle { width: parent.width height: parent.heigt color: "#fcdb00" } } } Component { id: desktopComponent ToolBarStyle { background: Rectangle { width: parent.width height: parent.heigt color: "red" } } }