Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] QML, Toolbar backgroud depending on WIndows or Android
QtWS25 Last Chance

[solved] QML, Toolbar backgroud depending on WIndows or Android

Scheduled Pinned Locked Moved General and Desktop
qmltoolcolorwindowsandroid
2 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HappyCoder
    wrote on 10 Apr 2015, 06:01 last edited by HappyCoder
    #1

    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?
    Thx

    toolBar: 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 }
        }
    }
    
    P 1 Reply Last reply 10 Apr 2015, 06:13
    0
    • H HappyCoder
      10 Apr 2015, 06:01

      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?
      Thx

      toolBar: 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 }
          }
      }
      
      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 10 Apr 2015, 06:13 last edited by
      #2

      @HappyCoder Since style requires a Component you can encapsulate in ToolBarStyle and assign it to style. The you can add a condition for style to load Component 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"
              }
          }
      }
      

      157

      1 Reply Last reply
      1

      2/2

      10 Apr 2015, 06:13

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved