Don't duplicate background resizing to contents
The code in Button is panel.implicitWidth: max(label+borders, backgroundImplicitSize) by setting the background implicitSize to be max(size, labels+borders) we just duplicate the functionality. This worked, but icon only buttons became smaller because we weren't setting the implicitHeight of the label properly. (two wrongs were making a right) We need to move the RowLayout inside an Item as we are modiyfing the preferredHeight of RowLayout, but this doesn't sync back to updating the implicitHeight which Button.qml uses. This fixes all binding loops and the rather broken icon only flat button. Change-Id: Id2f9c2ab37b2280ee69dc1473f388fe686e3327e
This commit is contained in:
parent
b2a5ebc926
commit
8a70067e8c
@ -34,9 +34,16 @@ QtQuickControlStyle.ButtonStyle {
|
|||||||
property int minimumWidth
|
property int minimumWidth
|
||||||
property int minimumHeight
|
property int minimumHeight
|
||||||
|
|
||||||
label: RowLayout {
|
label: Item {
|
||||||
|
//wrapper is needed as we are adjusting the preferredHeight of the layout from the default
|
||||||
|
//and the implicitHeight is implicitly read only
|
||||||
|
implicitHeight: buttonContent.Layout.preferredHeight
|
||||||
|
implicitWidth: buttonContent.implicitWidth
|
||||||
|
RowLayout {
|
||||||
id: buttonContent
|
id: buttonContent
|
||||||
|
anchors.fill: parent
|
||||||
spacing: units.smallSpacing
|
spacing: units.smallSpacing
|
||||||
|
|
||||||
Layout.preferredHeight: Math.max(units.iconSizes.small, label.implicitHeight)
|
Layout.preferredHeight: Math.max(units.iconSizes.small, label.implicitHeight)
|
||||||
|
|
||||||
property real minimumWidth: Layout.minimumWidth + style.padding.left + style.padding.right
|
property real minimumWidth: Layout.minimumWidth + style.padding.left + style.padding.right
|
||||||
@ -59,6 +66,10 @@ QtQuickControlStyle.ButtonStyle {
|
|||||||
id: icon
|
id: icon
|
||||||
source: control.iconName || control.iconSource
|
source: control.iconName || control.iconSource
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
|
implicitHeight: label.implicitHeight
|
||||||
|
implicitWidth: implicitHeight
|
||||||
|
|
||||||
Layout.minimumWidth: valid ? parent.height: 0
|
Layout.minimumWidth: valid ? parent.height: 0
|
||||||
Layout.maximumWidth: Layout.minimumWidth
|
Layout.maximumWidth: Layout.minimumWidth
|
||||||
visible: valid
|
visible: valid
|
||||||
@ -104,6 +115,7 @@ QtQuickControlStyle.ButtonStyle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
background: {
|
background: {
|
||||||
if (control.text.length == 0 && control.width == control.height && (control.parent && control.parent.checkedButton === undefined) && !control.flat) {
|
if (control.text.length == 0 && control.width == control.height && (control.parent && control.parent.checkedButton === undefined) && !control.flat) {
|
||||||
@ -117,7 +129,9 @@ QtQuickControlStyle.ButtonStyle {
|
|||||||
id: roundButtonComponent
|
id: roundButtonComponent
|
||||||
Item {
|
Item {
|
||||||
id: roundButtonDelegate
|
id: roundButtonDelegate
|
||||||
anchors.fill: parent
|
implicitHeight: Math.floor(theme.mSize(theme.defaultFont).height*1.6)
|
||||||
|
implicitWidth: implicitHeight
|
||||||
|
|
||||||
property QtObject margins: QtObject {
|
property QtObject margins: QtObject {
|
||||||
property int left: control.width/8
|
property int left: control.width/8
|
||||||
property int top: control.width/8
|
property int top: control.width/8
|
||||||
@ -166,13 +180,13 @@ QtQuickControlStyle.ButtonStyle {
|
|||||||
id: buttonComponent
|
id: buttonComponent
|
||||||
Item {
|
Item {
|
||||||
id: buttonSurface
|
id: buttonSurface
|
||||||
implicitHeight: Math.floor(Math.max(theme.mSize(theme.defaultFont).height*1.6, style.minimumHeight))
|
implicitHeight: Math.floor(theme.mSize(theme.defaultFont).height*1.6)
|
||||||
|
|
||||||
implicitWidth: {
|
implicitWidth: {
|
||||||
if (control.text.length == 0) {
|
if (control.text.length == 0) {
|
||||||
implicitHeight;
|
implicitHeight;
|
||||||
} else {
|
} else {
|
||||||
Math.max(theme.mSize(theme.defaultFont).width*12, style.minimumWidth);
|
Math.floor(theme.mSize(theme.defaultFont).width*12);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Connections {
|
Connections {
|
||||||
|
Loading…
Reference in New Issue
Block a user