0

This used to work till Qt 5.15

Button {
    text: "Test button"
        
    palette {
        button: "green"
    }
}

But not with Qt6

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Harris
  • 11
  • 1

1 Answers1

0

In Qt5 there are 2 groups of items with very common elements as I explain in this post: QML - Cannot assign to non-existent property "style".

In Qt5 the solution was not to confuse the imports (for example use a namespace) but in Qt6 the first group was removed so now only Qt Quick Controls 2 is used and that group has a different way of setting the button style:

import QtQuick
import QtQuick.Controls

Button {
    id: control
    text: qsTr("Button")

    contentItem: Text {
        text: control.text
        font: control.font
        opacity: enabled ? 1.0 : 0.3
        color: control.down ? "#17a81a" : "#21be2b"
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        elide: Text.ElideRight
    }

    background: Rectangle {
        implicitWidth: 100
        implicitHeight: 40
        opacity: enabled ? 1 : 0.3
        border.color: control.down ? "#17a81a" : "#21be2b"
        border.width: 1
        radius: 2
    }
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • This does not looks good. If we have to use rectangle to change background then what is the purpose of Button. – Harris Apr 27 '21 at 00:23
  • @Harris The Button is an Item that uses other items to define its appearance, a rectangle only draws the rectangle but does not have the signals and other aspects of the button. You just have to modify contentItem or background, you don't need both. – eyllanesc Apr 27 '21 at 00:33