Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to use qml code to change ToolBar background color (Qt Quick Controls 2.0)
Forum Update on Monday, May 27th 2025

How to use qml code to change ToolBar background color (Qt Quick Controls 2.0)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qtquickqtquickcontrolsmaterial design
6 Posts 3 Posters 11.1k 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.
  • A Offline
    A Offline
    Accelerated
    wrote on 27 Jul 2016, 15:06 last edited by Accelerated
    #1

    Hi guys,

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0
    import QtQuick.Controls.Material 2.0
    
    ApplicationWindow {
        id: window
    
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Page{
            id: page
            anchors.fill: parent
            header: ToolBar{
                id: toolBar
                Material.foreground: "white"
                Material.background: "white"
                Material.accent: "white"
                Label{
                    id: label
                    anchors.centerIn: parent
                    font.family: "Source Han Sans Light"
                    font.pixelSize: 24
                    color: "#f0f0f0"
                    text: "Main"
                }
            }
        }
    }
    
    

    ( ⊙ o ⊙ )

    I looked the example code, it seems to create a file called qtquickcontrols2.conf,

    but i find it is not convenient..such as changing theme color...

    Could you guys please teach me how to fix it? (=・ω・=)

    Thanks a lot. :)

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jpnurmi
      wrote on 27 Jul 2016, 16:24 last edited by
      #2

      You seem to be already altering the background and foreground colors, so I suppose your question is actually "how to run the app with the Material style"? You have several options. Besides the configuration file, you can use C++, a command line argument, or an environment variable. More details: http://doc.qt.io/qt-5/qtquickcontrols2-styles.html.

      A 1 Reply Last reply 28 Jul 2016, 01:21
      0
      • J jpnurmi
        27 Jul 2016, 16:24

        You seem to be already altering the background and foreground colors, so I suppose your question is actually "how to run the app with the Material style"? You have several options. Besides the configuration file, you can use C++, a command line argument, or an environment variable. More details: http://doc.qt.io/qt-5/qtquickcontrols2-styles.html.

        A Offline
        A Offline
        Accelerated
        wrote on 28 Jul 2016, 01:21 last edited by
        #3

        @jpnurmi
        Hi,

        Thanks for your answering.

        I can use the Material Style in Qt Quick, but my question is:

        How to change ToolBar background color?

        If you are free, you can run my code.

        😊😊

        J 1 Reply Last reply 28 Jul 2016, 05:51
        0
        • A Accelerated
          28 Jul 2016, 01:21

          @jpnurmi
          Hi,

          Thanks for your answering.

          I can use the Material Style in Qt Quick, but my question is:

          How to change ToolBar background color?

          If you are free, you can run my code.

          😊😊

          J Offline
          J Offline
          Julien B
          wrote on 28 Jul 2016, 05:51 last edited by Julien B
          #4

          HI @Accelerated,

          You can try to change the background property of the ToolBar (See Customizing ToolBar)

          import QtQuick 2.7
          import QtQuick.Controls 2.0
          import QtQuick.Layouts 1.0
          import QtQuick.Controls.Material 2.0
          
          ApplicationWindow {
              id: window
          
              visible: true
              width: 640
              height: 480
              title: qsTr("Hello World")
          
              Page{
                  id: page
                  anchors.fill: parent
                  header: ToolBar{
                      id: toolBar
                      Material.foreground: "white"
                      Material.background: "white"
                      Material.accent: "white"
                      Label{
                          id: label
                          anchors.centerIn: parent
                          font.family: "Source Han Sans Light"
                          font.pixelSize: 24
                          color: "#f0f0f0"
                          text: "Main"
          
                      }
                      background: Rectangle {
                          anchors.fill: parent
                          color : "red"
                      }
                  }
              }
          }
          
          
          1 Reply Last reply
          1
          • J Offline
            J Offline
            jpnurmi
            wrote on 28 Jul 2016, 08:21 last edited by
            #5

            The Material style uses the primary color for ToolBar:

            ToolBar {
                Material.primary: Material.Red
            }
            
            A 1 Reply Last reply 29 Jul 2016, 04:29
            3
            • J jpnurmi
              28 Jul 2016, 08:21

              The Material style uses the primary color for ToolBar:

              ToolBar {
                  Material.primary: Material.Red
              }
              
              A Offline
              A Offline
              Accelerated
              wrote on 29 Jul 2016, 04:29 last edited by
              #6

              @jpnurmi
              Hi jpnurmi!

              Thank you for you reply!

              I have solved my problem.

              (^__^) ~

              1 Reply Last reply
              0

              6/6

              29 Jul 2016, 04:29

              • Login

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