diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-03-16 09:38:54 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-03-27 12:52:34 +0100 |
commit | 05ae4d743b76aff4cc1a1c3d5aebc96e9f16f662 (patch) | |
tree | f88e7c310d8844e2efd6c58cbec945f36a69f73a | |
parent | 86794e82ea92cff3b36bbb58f813b625f0230e51 (diff) |
Controls: Improve various delegates
Their internal components should be bound, they should use required
properties, and they should prefer IDs over the "parent" property.
Change-Id: Iac61a4d7b9daf34928a1b41a29658e491e3ac39f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
17 files changed, 128 insertions, 31 deletions
diff --git a/src/quickcontrols/basic/ComboBox.qml b/src/quickcontrols/basic/ComboBox.qml index 33d1ef5907..5c71a4398e 100644 --- a/src/quickcontrols/basic/ComboBox.qml +++ b/src/quickcontrols/basic/ComboBox.qml @@ -1,6 +1,8 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Controls.impl import QtQuick.Templates as T @@ -18,6 +20,9 @@ T.ComboBox { rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing) delegate: ItemDelegate { + required property var model + required property int index + width: ListView.view.width text: model[control.textRole] palette.text: control.palette.text diff --git a/src/quickcontrols/basic/HorizontalHeaderView.qml b/src/quickcontrols/basic/HorizontalHeaderView.qml index 4f222d129b..9f571a8f62 100644 --- a/src/quickcontrols/basic/HorizontalHeaderView.qml +++ b/src/quickcontrols/basic/HorizontalHeaderView.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Templates as T @@ -16,6 +18,10 @@ T.HorizontalHeaderView { implicitHeight: Math.max(1, contentHeight) delegate: Rectangle { + id: delegate + + required property var model + // Qt6: add cellPadding (and font etc) as public API in headerview readonly property real cellPadding: 8 @@ -26,9 +32,9 @@ T.HorizontalHeaderView { Label { id: text - text: model[control.textRole] - width: parent.width - height: parent.height + text: delegate.model[control.textRole] + width: delegate.width + height: delegate.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "#ff26282a" diff --git a/src/quickcontrols/basic/VerticalHeaderView.qml b/src/quickcontrols/basic/VerticalHeaderView.qml index 435b320d9c..52a9bcb876 100644 --- a/src/quickcontrols/basic/VerticalHeaderView.qml +++ b/src/quickcontrols/basic/VerticalHeaderView.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Templates as T @@ -16,6 +18,10 @@ T.VerticalHeaderView { implicitHeight: syncView ? syncView.height : 0 delegate: Rectangle { + id: delegate + + required property var model + // Qt6: add cellPadding (and font etc) as public API in headerview readonly property real cellPadding: 8 @@ -26,9 +32,9 @@ T.VerticalHeaderView { Label { id: text - text: model[control.textRole] - width: parent.width - height: parent.height + text: delegate.model[control.textRole] + width: delegate.width + height: delegate.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "#ff26282a" diff --git a/src/quickcontrols/doc/snippets/qtquickcontrols-combobox-custom.qml b/src/quickcontrols/doc/snippets/qtquickcontrols-combobox-custom.qml index f1d721b24c..e9fd0e4984 100644 --- a/src/quickcontrols/doc/snippets/qtquickcontrols-combobox-custom.qml +++ b/src/quickcontrols/doc/snippets/qtquickcontrols-combobox-custom.qml @@ -2,6 +2,8 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only //! [file] +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Controls @@ -10,9 +12,14 @@ ComboBox { model: ["First", "Second", "Third"] delegate: ItemDelegate { + id: delegate + + required property var model + required property int index + width: control.width contentItem: Text { - text: model[control.textRole] + text: delegate.model[control.textRole] color: "#21be2b" font: control.font elide: Text.ElideRight diff --git a/src/quickcontrols/fusion/ComboBox.qml b/src/quickcontrols/fusion/ComboBox.qml index 6344dc73db..609f294d6f 100644 --- a/src/quickcontrols/fusion/ComboBox.qml +++ b/src/quickcontrols/fusion/ComboBox.qml @@ -1,6 +1,8 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Window import QtQuick.Templates as T @@ -21,6 +23,9 @@ T.ComboBox { rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing) delegate: MenuItem { + required property var model + required property int index + width: ListView.view.width text: model[control.textRole] font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal diff --git a/src/quickcontrols/fusion/HorizontalHeaderView.qml b/src/quickcontrols/fusion/HorizontalHeaderView.qml index b82c7ba22e..dbea743aca 100644 --- a/src/quickcontrols/fusion/HorizontalHeaderView.qml +++ b/src/quickcontrols/fusion/HorizontalHeaderView.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Templates as T import QtQuick.Controls.Fusion.impl @@ -17,6 +19,10 @@ T.HorizontalHeaderView { implicitHeight: Math.max(1, contentHeight) delegate: Rectangle { + id: delegate + + required property var model + // Qt6: add cellPadding (and font etc) as public API in headerview readonly property real cellPadding: 8 @@ -37,9 +43,9 @@ T.HorizontalHeaderView { Label { id: text - text: model[control.textRole] - width: parent.width - height: parent.height + text: delegate.model[control.textRole] + width: delegate.width + height: delegate.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } diff --git a/src/quickcontrols/fusion/VerticalHeaderView.qml b/src/quickcontrols/fusion/VerticalHeaderView.qml index b65edaa8d6..c2cb281a24 100644 --- a/src/quickcontrols/fusion/VerticalHeaderView.qml +++ b/src/quickcontrols/fusion/VerticalHeaderView.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Templates as T import QtQuick.Controls.Fusion.impl @@ -17,6 +19,10 @@ T.VerticalHeaderView { implicitHeight: syncView ? syncView.height : 0 delegate: Rectangle { + id: delegate + + required property var model + // Qt6: add cellPadding (and font etc) as public API in headerview readonly property real cellPadding: 8 @@ -36,9 +42,9 @@ T.VerticalHeaderView { Label { id: text - text: model[control.textRole] - width: parent.width - height: parent.height + text: delegate.model[control.textRole] + width: delegate.width + height: delegate.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } diff --git a/src/quickcontrols/imagine/ComboBox.qml b/src/quickcontrols/imagine/ComboBox.qml index 73a3708641..582b820b82 100644 --- a/src/quickcontrols/imagine/ComboBox.qml +++ b/src/quickcontrols/imagine/ComboBox.qml @@ -1,6 +1,8 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Window import QtQuick.Templates as T @@ -25,6 +27,9 @@ T.ComboBox { bottomInset: background ? -background.bottomInset || 0 : 0 delegate: ItemDelegate { + required property var model + required property int index + width: ListView.view.width text: model[control.textRole] font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal diff --git a/src/quickcontrols/imagine/HorizontalHeaderView.qml b/src/quickcontrols/imagine/HorizontalHeaderView.qml index 4f222d129b..9f571a8f62 100644 --- a/src/quickcontrols/imagine/HorizontalHeaderView.qml +++ b/src/quickcontrols/imagine/HorizontalHeaderView.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Templates as T @@ -16,6 +18,10 @@ T.HorizontalHeaderView { implicitHeight: Math.max(1, contentHeight) delegate: Rectangle { + id: delegate + + required property var model + // Qt6: add cellPadding (and font etc) as public API in headerview readonly property real cellPadding: 8 @@ -26,9 +32,9 @@ T.HorizontalHeaderView { Label { id: text - text: model[control.textRole] - width: parent.width - height: parent.height + text: delegate.model[control.textRole] + width: delegate.width + height: delegate.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "#ff26282a" diff --git a/src/quickcontrols/imagine/VerticalHeaderView.qml b/src/quickcontrols/imagine/VerticalHeaderView.qml index 435b320d9c..52a9bcb876 100644 --- a/src/quickcontrols/imagine/VerticalHeaderView.qml +++ b/src/quickcontrols/imagine/VerticalHeaderView.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Templates as T @@ -16,6 +18,10 @@ T.VerticalHeaderView { implicitHeight: syncView ? syncView.height : 0 delegate: Rectangle { + id: delegate + + required property var model + // Qt6: add cellPadding (and font etc) as public API in headerview readonly property real cellPadding: 8 @@ -26,9 +32,9 @@ T.VerticalHeaderView { Label { id: text - text: model[control.textRole] - width: parent.width - height: parent.height + text: delegate.model[control.textRole] + width: delegate.width + height: delegate.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: "#ff26282a" diff --git a/src/quickcontrols/material/ComboBox.qml b/src/quickcontrols/material/ComboBox.qml index 30ef4d175d..28da813b37 100644 --- a/src/quickcontrols/material/ComboBox.qml +++ b/src/quickcontrols/material/ComboBox.qml @@ -1,6 +1,8 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Window import QtQuick.Controls.impl @@ -27,6 +29,9 @@ T.ComboBox { Material.foreground: flat ? undefined : Material.primaryTextColor delegate: MenuItem { + required property var model + required property int index + width: ListView.view.width text: model[control.textRole] Material.foreground: control.currentIndex === index ? ListView.view.contentItem.Material.accent : ListView.view.contentItem.Material.foreground diff --git a/src/quickcontrols/material/HorizontalHeaderView.qml b/src/quickcontrols/material/HorizontalHeaderView.qml index 21f9bbb47c..76060d8e83 100644 --- a/src/quickcontrols/material/HorizontalHeaderView.qml +++ b/src/quickcontrols/material/HorizontalHeaderView.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Templates as T import QtQuick.Controls.Material @@ -18,6 +20,10 @@ T.HorizontalHeaderView { implicitHeight: Math.max(1, contentHeight) delegate: Rectangle { + id: delegate + + required property var model + // Qt6: add cellPadding (and font etc) as public API in headerview readonly property real cellPadding: 8 @@ -27,9 +33,9 @@ T.HorizontalHeaderView { Label { id: text - text: model[control.textRole] - width: parent.width - height: parent.height + text: delegate.model[control.textRole] + width: delegate.width + height: delegate.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: enabled ? control.Material.foreground : control.Material.hintTextColor diff --git a/src/quickcontrols/material/VerticalHeaderView.qml b/src/quickcontrols/material/VerticalHeaderView.qml index 1aaca6f0b0..0646f6135d 100644 --- a/src/quickcontrols/material/VerticalHeaderView.qml +++ b/src/quickcontrols/material/VerticalHeaderView.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Templates as T import QtQuick.Controls.Material @@ -18,6 +20,10 @@ T.VerticalHeaderView { implicitHeight: syncView ? syncView.height : 0 delegate: Rectangle { + id: delegate + + required property var model + // Qt6: add cellPadding (and font etc) as public API in headerview readonly property real cellPadding: 8 @@ -27,9 +33,9 @@ T.VerticalHeaderView { Label { id: text - text: model[control.textRole] - width: parent.width - height: parent.height + text: delegate.model[control.textRole] + width: delegate.width + height: delegate.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: enabled ? control.Material.foreground : control.Material.hintTextColor diff --git a/src/quickcontrols/universal/ComboBox.qml b/src/quickcontrols/universal/ComboBox.qml index cecffb10fa..0793416b69 100644 --- a/src/quickcontrols/universal/ComboBox.qml +++ b/src/quickcontrols/universal/ComboBox.qml @@ -1,6 +1,8 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Window import QtQuick.Controls.impl @@ -22,6 +24,9 @@ T.ComboBox { Universal.theme: editable && activeFocus ? Universal.Light : undefined delegate: ItemDelegate { + required property var model + required property int index + width: ListView.view.width text: model[control.textRole] font.weight: control.currentIndex === index ? Font.DemiBold : Font.Normal diff --git a/src/quickcontrols/universal/HorizontalHeaderView.qml b/src/quickcontrols/universal/HorizontalHeaderView.qml index c2e28f491b..f792a1e690 100644 --- a/src/quickcontrols/universal/HorizontalHeaderView.qml +++ b/src/quickcontrols/universal/HorizontalHeaderView.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Controls.impl import QtQuick.Templates as T @@ -19,6 +21,10 @@ T.HorizontalHeaderView { implicitHeight: Math.max(1, contentHeight) delegate: Rectangle { + id: delegate + + required property var model + // Qt6: add cellPadding (and font etc) as public API in headerview readonly property real cellPadding: 8 @@ -28,9 +34,9 @@ T.HorizontalHeaderView { Label { id: text - text: model[control.textRole] - width: parent.width - height: parent.height + text: delegate.model[control.textRole] + width: delegate.width + height: delegate.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: Color.transparent(control.Universal.foreground, enabled ? 1.0 : 0.2) diff --git a/src/quickcontrols/universal/VerticalHeaderView.qml b/src/quickcontrols/universal/VerticalHeaderView.qml index 3d664b2b66..6e4540d66a 100644 --- a/src/quickcontrols/universal/VerticalHeaderView.qml +++ b/src/quickcontrols/universal/VerticalHeaderView.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Controls.impl import QtQuick.Templates as T @@ -19,6 +21,10 @@ T.VerticalHeaderView { implicitHeight: syncView ? syncView.height : 0 delegate: Rectangle { + id: delegate + + required property var model + // Qt6: add cellPadding (and font etc) as public API in headerview readonly property real cellPadding: 8 @@ -28,9 +34,9 @@ T.VerticalHeaderView { Label { id: text - text: model[control.textRole] - width: parent.width - height: parent.height + text: delegate.model[control.textRole] + width: delegate.width + height: delegate.height horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter color: Color.transparent(control.Universal.foreground, enabled ? 1.0 : 0.2) diff --git a/src/quicknativestyle/controls/DefaultComboBox.qml b/src/quicknativestyle/controls/DefaultComboBox.qml index 4894d60e5e..0876c522b3 100644 --- a/src/quicknativestyle/controls/DefaultComboBox.qml +++ b/src/quicknativestyle/controls/DefaultComboBox.qml @@ -1,6 +1,8 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +pragma ComponentBehavior: Bound + import QtQuick import QtQuick.Window import QtQuick.Controls @@ -56,6 +58,9 @@ T.ComboBox { } delegate: ItemDelegate { + required property var model + required property int index + width: ListView.view.width text: model[control.textRole] palette.text: control.palette.text |