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. ToolButton of QtQuick control 2 cannot resize icons
Forum Update on Monday, May 27th 2025

ToolButton of QtQuick control 2 cannot resize icons

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 3 Posters 1.2k 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.
  • thamT Offline
    thamT Offline
    tham
    wrote on last edited by tham
    #1

    I want to resize the svg icon to 80*80, but the contentItem of Toolbar always show me original size of the icon. How could I resize the icon of the ToolBar?Thanks

    import QtQuick 2.6
    import QtQuick.Controls 2.0
    
    ApplicationWindow {
        id: window
        width: 360
        height: 520
        visible: true
        title: "Qt Quick Controls 2"
    
        header: ToolBar {
            Material.foreground: "white"
    
            RowLayout {
                spacing: 20
                anchors.fill: parent
    
                ToolButton {
                    width: 80
                    height: width
                    contentItem: Image{
                        fillMode: Image.PreserveAspectFit
                        horizontalAlignment: Image.AlignHCenter
                        verticalAlignment: Image.AlignVCenter
                        source: "qrc:/icons/menu-icon.svg"
                        width:80
                        height:80
                    }                
                }
            }
        }
    }
    
    CharlieGC 1 Reply Last reply
    0
    • thamT tham

      I want to resize the svg icon to 80*80, but the contentItem of Toolbar always show me original size of the icon. How could I resize the icon of the ToolBar?Thanks

      import QtQuick 2.6
      import QtQuick.Controls 2.0
      
      ApplicationWindow {
          id: window
          width: 360
          height: 520
          visible: true
          title: "Qt Quick Controls 2"
      
          header: ToolBar {
              Material.foreground: "white"
      
              RowLayout {
                  spacing: 20
                  anchors.fill: parent
      
                  ToolButton {
                      width: 80
                      height: width
                      contentItem: Image{
                          fillMode: Image.PreserveAspectFit
                          horizontalAlignment: Image.AlignHCenter
                          verticalAlignment: Image.AlignVCenter
                          source: "qrc:/icons/menu-icon.svg"
                          width:80
                          height:80
                      }                
                  }
              }
          }
      }
      
      CharlieGC Offline
      CharlieGC Offline
      CharlieG
      wrote on last edited by
      #2

      @tham
      Hi,

      Have your tester with an Image in a Rectangle ?

      Rectangle{
          width: 80
          height: 80
          ....
          Image {
               anchors.fill : parent
               ....
          }
      }
      
      1 Reply Last reply
      0
      • S Offline
        S Offline
        sardar
        wrote on last edited by sardar
        #3

        @tham

        use sourceSize property in Image :

        sourceSize.width: 80
        sourceSize.height: 80
        

        like this code :

        contentItem: Image{
             fillMode: Image.PreserveAspectFit
             horizontalAlignment: Image.AlignHCenter
             verticalAlignment: Image.AlignVCenter
             source: "qrc:/icons/menu-icon.svg"
             sourceSize.width:80
             sourceSize.height:80
        }
        
        1 Reply Last reply
        1

        • Login

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