ToolButton of QtQuick control 2 cannot resize icons



  • 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
                    }                
                }
            }
        }
    }
    


  • @tham
    Hi,

    Have your tester with an Image in a Rectangle ?

    Rectangle{
        width: 80
        height: 80
        ....
        Image {
             anchors.fill : parent
             ....
        }
    }
    


  • @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
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.