Home > OS >  QML change Button icon size
QML change Button icon size

Time:12-15

How can I change the size of a Button icon? If i set icon.height and icon.width it gives me this error:

QML IconLabel: Binding loop detected for property "icon"

    Button {
        Layout.preferredHeight: parent.height * 0.2
        Layout.preferredWidth: parent.width
        Layout.row: 4
        Layout.column: 0
        Layout.columnSpan: 3
        icon.source: "qrc:/media/dazn.png"
        icon.height: height
        icon.width: width
    }

CodePudding user response:

You should indeed not bind to height and width, since these properties are indirectly calculated from the icon size plus the padding, leading to the mentioned binding loop. Not sure about your exact intentions, but you could bind to Layout.preferredHeight and Layout.preferredWidth

Button {
    Layout.preferredHeight: parent.height * 0.2
    Layout.preferredWidth: parent.width
    Layout.row: 4
    Layout.column: 0
    Layout.columnSpan: 3
    icon.source: "qrc:/media/dazn.png"
    icon.height: Layout.preferredHeight
    icon.width: Layout.preferredWidth
}

It seems the icon is still constrained by some limits (inside IconLabel), however it will get as big as allowed.

  • Related