[solved] QML, Toolbar backgroud depending on WIndows or Android
General and Desktop
2
Posts
2
Posters
1.4k
Views
2
Watching
-
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 } } } -
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
stylerequires aComponentyou can encapsulate inToolBarStyleand assign it tostyle. The you can add a condition forstyleto loadComponentas 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" } } }