Windows, Button.qml: inherit from DefaultButton, and remove duplicated code

Let Button.qml inherit from DefaultButton.qml, since they share
a lot of the same code. This then means we can remove a lot of
the duplicated code. We will also get any bug fixes done to
DefaultButton.qml for free, like ensuring that you can use
Button together with custom background delegates.

Pick-to: 6.2 6.1
Fixes: QTBUG-95544
Change-Id: Ie5edae58a44ae6e7b86cc016a07439844e387b1e
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
Richard Moe Gustavsen 2021-08-12 13:25:27 +02:00
parent 20054ba885
commit 9738d49b65
1 changed files with 1 additions and 22 deletions

View File

@ -36,27 +36,11 @@
import QtQuick
import QtQuick.Controls.impl
import QtQuick.Templates as T
import QtQuick.NativeStyle as NativeStyle
T.Button {
NativeStyle.DefaultButton {
id: control
readonly property bool __nativeBackground: background instanceof NativeStyle.StyleItem
// Since QQuickControl will subtract the insets from the control size to
// figure out the background size, we need to reverse that here, otherwise
// the control ends up too big.
implicitWidth: implicitBackgroundWidth + leftInset + rightInset
implicitHeight: implicitBackgroundHeight + topInset + bottomInset
font.pixelSize: __nativeBackground ? background.styleFont(control).pixelSize : undefined
leftPadding: __nativeBackground ? background.contentPadding.left : 5
rightPadding: __nativeBackground ? background.contentPadding.right : 5
topPadding: __nativeBackground ? background.contentPadding.top : 5
bottomPadding: __nativeBackground ? background.contentPadding.bottom : 5
background: NativeStyle.Button {
control: control
contentWidth: contentItem.implicitWidth
@ -79,11 +63,6 @@ T.Button {
Behavior on opacity { NumberAnimation { duration: hoverButton.transitionDuration } }
}
icon.width: 24
icon.height: 24
icon.color: control.checked || control.highlighted ? control.palette.brightText :
control.flat && !control.down ? (control.visualFocus ? control.palette.highlight : control.palette.windowText) : control.palette.buttonText
contentItem: IconLabel {
spacing: control.spacing
mirrored: control.mirrored