aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDilek Akcay <dilek.akcay@qt.io>2026-09-25 11:22:57 +0200
committerDilek Akcay <dilek.akcay@qt.io>2026-09-30 16:03:57 +0000
commit7beb35bdb18e447cb0509a2b66dc45d4a5a21f39 (patch)
tree0f6270a1ba7f9f11a1a43a52984330a1a400130f
parent229d3f6de529238fde08f75f1f00684fe12970db (diff)
StyleKit: Implement TableViewDelegate
Pick-to: 6.12 Change-Id: I09f75b8eab46ae5b640eec8b0d4c51ec45ecfbdb Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/labs/stylekit/CMakeLists.txt1
-rw-r--r--src/labs/stylekit/TableViewDelegate.qml98
-rw-r--r--src/labs/stylekit/doc/snippets/ControlsSnippets.qml17
-rw-r--r--src/labs/stylekit/doc/snippets/ReferenceFallbackStyle.qml13
-rw-r--r--src/labs/stylekit/impl/FallbackStyle.qml13
-rw-r--r--src/labs/stylekit/qqstylekitcontrols.cpp11
-rw-r--r--src/labs/stylekit/qqstylekitcontrols_p.h3
-rw-r--r--src/labs/stylekit/qqstylekitpropertyresolver.cpp3
-rw-r--r--src/labs/stylekit/qqstylekitreader.cpp89
-rw-r--r--src/labs/stylekit/qqstylekitreader_p.h1
-rw-r--r--src/labs/stylekit/qqstylekittheme.cpp1
11 files changed, 205 insertions, 45 deletions
diff --git a/src/labs/stylekit/CMakeLists.txt b/src/labs/stylekit/CMakeLists.txt
index 01153b518f..171a5606b9 100644
--- a/src/labs/stylekit/CMakeLists.txt
+++ b/src/labs/stylekit/CMakeLists.txt
@@ -74,6 +74,7 @@ qt_internal_add_qml_module(LabsStyleKit
TextField.qml
TabBar.qml
TabButton.qml
+ TableViewDelegate.qml
ToolBar.qml
ToolButton.qml
ToolSeparator.qml
diff --git a/src/labs/stylekit/TableViewDelegate.qml b/src/labs/stylekit/TableViewDelegate.qml
new file mode 100644
index 0000000000..d5e40ca17d
--- /dev/null
+++ b/src/labs/stylekit/TableViewDelegate.qml
@@ -0,0 +1,98 @@
+// Copyright (C) 2026 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
+// Qt-Security score:significant reason:default
+
+import QtQuick
+import QtQuick.Controls.impl
+import QtQuick.Templates as T
+import Qt.labs.StyleKit
+import Qt.labs.StyleKit.impl
+
+T.TableViewDelegate {
+ id: control
+
+ implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
+ implicitContentWidth + leftPadding + rightPadding)
+ implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
+ implicitContentHeight + topPadding + bottomPadding)
+
+ required property int row
+ required property int column
+ required property var model
+
+ highlighted: control.selected
+
+ leftPadding: styleReader.leftPadding
+ rightPadding: styleReader.rightPadding
+ topPadding: styleReader.topPadding
+ bottomPadding: styleReader.bottomPadding
+
+ leftInset: styleReader.background.leftMargin
+ rightInset: styleReader.background.rightMargin
+ topInset: styleReader.background.topMargin
+ bottomInset: styleReader.background.bottomMargin
+
+ spacing: styleReader.spacing
+ font: styleReader.font
+
+ StyleVariation.controlType: styleReader.controlType
+ StyleReader {
+ id: styleReader
+ controlType: StyleReader.TableViewDelegate
+ enabled: control.enabled
+ // Cell delegates are recycled, so giving one real Qt keyboard focus would
+ // clash with what "current" means and in practice activeFocus never
+ // triggers here anyway. We map focused to current instead.
+ focused: control.current
+ checked: control.checked
+ hovered: control.hovered
+ pressed: control.pressed
+ highlighted: control.highlighted
+ palette: control.palette
+ }
+
+ contentItem: Label {
+ clip: false
+ text: control.model.display ?? ""
+ elide: Text.ElideRight
+ color: styleReader.text.color
+ font: styleReader.font
+ visible: !control.editing
+
+ horizontalAlignment: styleReader.text.alignment & Qt.AlignHorizontal_Mask
+ verticalAlignment: styleReader.text.alignment & Qt.AlignVertical_Mask
+ padding: styleReader.text.padding
+ leftPadding: styleReader.text.leftPadding
+ rightPadding: styleReader.text.rightPadding
+ bottomPadding: styleReader.text.bottomPadding
+ topPadding: styleReader.text.topPadding
+ }
+
+ TableView.editDelegate: FocusScope {
+ width: parent.width
+ height: parent.height
+
+ TableView.onCommit: {
+ let model = control.tableView.model
+ if (!model)
+ return
+ const index = model.index(control.row, control.column)
+ if (!model.setData(index, textField.text, Qt.EditRole))
+ console.warn("The model does not allow setting the EditRole data.")
+ }
+
+ Component.onCompleted: textField.selectAll()
+
+ TextField {
+ id: textField
+ anchors.fill: parent
+ text: control.model.edit ?? control.model.display ?? ""
+ focus: true
+ }
+ }
+
+ background: BackgroundDelegate {
+ quickControl: control
+ backgroundStyle: styleReader.background
+ }
+}
diff --git a/src/labs/stylekit/doc/snippets/ControlsSnippets.qml b/src/labs/stylekit/doc/snippets/ControlsSnippets.qml
index d677c11124..710f860a16 100644
--- a/src/labs/stylekit/doc/snippets/ControlsSnippets.qml
+++ b/src/labs/stylekit/doc/snippets/ControlsSnippets.qml
@@ -835,6 +835,23 @@ ApplicationWindow {
}
//! [tabButton]
+ //! [tableViewDelegate]
+ tableViewDelegate {
+ text.alignment: Qt.AlignVCenter | Qt.AlignLeft
+ background {
+ radius: 0
+ color: "white"
+ border.width: 0
+ }
+ hovered.background.color: "white"
+ highlighted.background.color: "darkslategray"
+ highlighted.hovered.background.color: "darkslategray"
+ focused {
+ background.border.width: 2
+ }
+ }
+ //! [tableViewDelegate]
+
//! [textArea]
textArea {
// Add some space between the text and the border of the text area
diff --git a/src/labs/stylekit/doc/snippets/ReferenceFallbackStyle.qml b/src/labs/stylekit/doc/snippets/ReferenceFallbackStyle.qml
index f5874f3fb4..a45b5136a5 100644
--- a/src/labs/stylekit/doc/snippets/ReferenceFallbackStyle.qml
+++ b/src/labs/stylekit/doc/snippets/ReferenceFallbackStyle.qml
@@ -654,6 +654,19 @@ BaseStyle {
}
}
+ tableViewDelegate {
+ text.alignment: Qt.AlignVCenter | Qt.AlignLeft
+ background {
+ radius: 0
+ color: __baseWhite
+ border.width: 0
+ }
+ hovered.background.color: __baseWhite
+ highlighted.background.color: __strokeStrong
+ highlighted.hovered.background.color: __strokeStrong
+ focused.background.border.width: 2
+ }
+
textField {
text.alignment: Qt.AlignVCenter
background {
diff --git a/src/labs/stylekit/impl/FallbackStyle.qml b/src/labs/stylekit/impl/FallbackStyle.qml
index 6f9aad4469..4f7430363f 100644
--- a/src/labs/stylekit/impl/FallbackStyle.qml
+++ b/src/labs/stylekit/impl/FallbackStyle.qml
@@ -705,6 +705,19 @@ BaseStyle {
}
}
+ tableViewDelegate {
+ text.alignment: Qt.AlignVCenter | Qt.AlignLeft
+ background {
+ radius: 0
+ color: __baseWhite
+ border.width: 0
+ }
+ hovered.background.color: __baseWhite
+ highlighted.background.color: __strokeStrong
+ highlighted.hovered.background.color: __strokeStrong
+ focused.background.border.width: 2
+ }
+
textField {
text.alignment: Qt.AlignVCenter
background {
diff --git a/src/labs/stylekit/qqstylekitcontrols.cpp b/src/labs/stylekit/qqstylekitcontrols.cpp
index 73fc78b4d4..31880a9482 100644
--- a/src/labs/stylekit/qqstylekitcontrols.cpp
+++ b/src/labs/stylekit/qqstylekitcontrols.cpp
@@ -544,6 +544,16 @@ QT_BEGIN_NAMESPACE
\snippet ControlsSnippets.qml tabButton
*/
+/*
+ \qmlproperty ControlStyle StylableControls::tableViewDelegate
+
+ Grouped property for styling \l [QtQuickControls]{TableViewDelegate}.
+
+ Unset properties fall back to \l itemDelegate.
+
+ \snippet ControlsSnippets.qml tableViewDelegate
+*/
+
/*!
\qmlproperty ControlStyle StylableControls::textArea
@@ -728,6 +738,7 @@ IMPLEMENT_ACCESSORS(switchControl, QQStyleKitReader::ControlType::SwitchControl)
IMPLEMENT_ACCESSORS(switchDelegate, QQStyleKitReader::ControlType::SwitchDelegate)
IMPLEMENT_ACCESSORS(tabBar, QQStyleKitReader::ControlType::TabBar)
IMPLEMENT_ACCESSORS(tabButton, QQStyleKitReader::ControlType::TabButton)
+IMPLEMENT_ACCESSORS(tableViewDelegate, QQStyleKitReader::ControlType::TableViewDelegate)
IMPLEMENT_ACCESSORS(textField, QQStyleKitReader::ControlType::TextField)
IMPLEMENT_ACCESSORS(textInput, QQStyleKitReader::ControlType::TextInput)
IMPLEMENT_ACCESSORS(toolBar, QQStyleKitReader::ControlType::ToolBar)
diff --git a/src/labs/stylekit/qqstylekitcontrols_p.h b/src/labs/stylekit/qqstylekitcontrols_p.h
index f9536a2238..019223028d 100644
--- a/src/labs/stylekit/qqstylekitcontrols_p.h
+++ b/src/labs/stylekit/qqstylekitcontrols_p.h
@@ -54,6 +54,7 @@ class QQStyleKitControls : public QObject, public QQmlParserStatus
Q_PROPERTY(QQStyleKitControl *spinBox READ spinBox WRITE set_spinBox NOTIFY spinBoxChanged FINAL)
Q_PROPERTY(QQStyleKitControl *tabBar READ tabBar WRITE set_tabBar NOTIFY tabBarChanged FINAL)
Q_PROPERTY(QQStyleKitControl *tabButton READ tabButton WRITE set_tabButton NOTIFY tabButtonChanged FINAL)
+ Q_PROPERTY(QQStyleKitControl *tableViewDelegate READ tableViewDelegate WRITE set_tableViewDelegate NOTIFY tableViewDelegateChanged FINAL)
Q_PROPERTY(QQStyleKitControl *textField READ textField WRITE set_textField NOTIFY textFieldChanged FINAL)
Q_PROPERTY(QQStyleKitControl *textInput READ textInput WRITE set_textInput NOTIFY textInputChanged FINAL)
Q_PROPERTY(QQStyleKitControl *toolBar READ toolBar WRITE set_toolBar NOTIFY toolBarChanged FINAL)
@@ -117,6 +118,7 @@ public:
IMPLEMENT_ACCESSORS(spinBox)
IMPLEMENT_ACCESSORS(tabBar)
IMPLEMENT_ACCESSORS(tabButton)
+ IMPLEMENT_ACCESSORS(tableViewDelegate)
IMPLEMENT_ACCESSORS(textField)
IMPLEMENT_ACCESSORS(textInput)
IMPLEMENT_ACCESSORS(toolBar)
@@ -177,6 +179,7 @@ signals:
void spinBoxChanged();
void tabBarChanged();
void tabButtonChanged();
+ void tableViewDelegateChanged();
void textFieldChanged();
void textInputChanged();
void toolBarChanged();
diff --git a/src/labs/stylekit/qqstylekitpropertyresolver.cpp b/src/labs/stylekit/qqstylekitpropertyresolver.cpp
index 4ffb0cc060..d4d060a3d3 100644
--- a/src/labs/stylekit/qqstylekitpropertyresolver.cpp
+++ b/src/labs/stylekit/qqstylekitpropertyresolver.cpp
@@ -65,7 +65,8 @@ const QList<QQStyleKitExtendableControlType> QQStyleKitPropertyResolver::baseTyp
case QQStyleKitReader::CheckDelegate:
case QQStyleKitReader::RadioDelegate:
case QQStyleKitReader::SwipeDelegate:
- case QQStyleKitReader::SwitchDelegate: {
+ case QQStyleKitReader::SwitchDelegate:
+ case QQStyleKitReader::TableViewDelegate: {
static QList<QQStyleKitExtendableControlType> t =
{ QQStyleKitReader::ItemDelegate, QQStyleKitReader::Control };
return t; }
diff --git a/src/labs/stylekit/qqstylekitreader.cpp b/src/labs/stylekit/qqstylekitreader.cpp
index d55b117258..d61d314e96 100644
--- a/src/labs/stylekit/qqstylekitreader.cpp
+++ b/src/labs/stylekit/qqstylekitreader.cpp
@@ -62,50 +62,51 @@ QT_BEGIN_NAMESPACE
below, or to a \l {CustomControl::controlType}{custom control type} defined in the
\l Style.
- \value StyleReader.BusyIndicator \l {BusyIndicator}
- \value StyleReader.Button \l {Button}
- \value StyleReader.CheckBox \l {CheckBox}
- \value StyleReader.CheckDelegate \l {CheckDelegate}
- \value StyleReader.ComboBox \l {ComboBox}
- \value StyleReader.DelayButton \l {DelayButton}
- \value StyleReader.Dial \l {Dial}
- \value StyleReader.Dialog \l {Dialog}
- \value StyleReader.DialogButtonBox \l {DialogButtonBox}
- \value StyleReader.Drawer \l {Drawer}
- \value StyleReader.Frame \l {Frame}
- \value StyleReader.GroupBox \l {GroupBox}
- \value StyleReader.ItemDelegate \l {ItemDelegate}
- \value StyleReader.Label \l {Label}
- \value StyleReader.Menu \l {Menu}
- \value StyleReader.MenuBar \l {MenuBar}
- \value StyleReader.MenuBarItem \l {MenuBarItem}
- \value StyleReader.MenuItem \l {MenuItem}
- \value StyleReader.MenuSeparator \l {MenuSeparator}
- \value StyleReader.Page \l {Page}
- \value StyleReader.PageIndicator \l {PageIndicator}
- \value StyleReader.Pane \l {Pane}
- \value StyleReader.Popup \l {Popup}
- \value StyleReader.ProgressBar \l {ProgressBar}
- \value StyleReader.RadioButton \l {RadioButton}
- \value StyleReader.RadioDelegate \l {RadioDelegate}
- \value StyleReader.RoundButton \l {RoundButton}
- \value StyleReader.ScrollBar \l {ScrollBar}
- \value StyleReader.ScrollView \l {ScrollView}
- \value StyleReader.SearchField \l {SearchField}
- \value StyleReader.Slider \l {Slider}
- \value StyleReader.SpinBox \l {SpinBox}
- \value StyleReader.SwipeDelegate \l {SwipeDelegate}
- \value StyleReader.Switch \l {Switch}
- \value StyleReader.SwitchDelegate \l {SwitchDelegate}
- \value StyleReader.TabBar \l {TabBar}
- \value StyleReader.TabButton \l {TabButton}
- \value StyleReader.TextArea \l {TextArea}
- \value StyleReader.TextField \l {TextField}
- \value StyleReader.ToolBar \l {ToolBar}
- \value StyleReader.ToolButton \l {ToolButton}
- \value StyleReader.ToolSeparator \l {ToolSeparator}
- \value StyleReader.ToolTip \l {ToolTip}
- \value StyleReader.Tumbler \l {Tumbler}
+ \value StyleReader.BusyIndicator \l {BusyIndicator}
+ \value StyleReader.Button \l {Button}
+ \value StyleReader.CheckBox \l {CheckBox}
+ \value StyleReader.CheckDelegate \l {CheckDelegate}
+ \value StyleReader.ComboBox \l {ComboBox}
+ \value StyleReader.DelayButton \l {DelayButton}
+ \value StyleReader.Dial \l {Dial}
+ \value StyleReader.Dialog \l {Dialog}
+ \value StyleReader.DialogButtonBox \l {DialogButtonBox}
+ \value StyleReader.Drawer \l {Drawer}
+ \value StyleReader.Frame \l {Frame}
+ \value StyleReader.GroupBox \l {GroupBox}
+ \value StyleReader.ItemDelegate \l {ItemDelegate}
+ \value StyleReader.Label \l {Label}
+ \value StyleReader.Menu \l {Menu}
+ \value StyleReader.MenuBar \l {MenuBar}
+ \value StyleReader.MenuBarItem \l {MenuBarItem}
+ \value StyleReader.MenuItem \l {MenuItem}
+ \value StyleReader.MenuSeparator \l {MenuSeparator}
+ \value StyleReader.Page \l {Page}
+ \value StyleReader.PageIndicator \l {PageIndicator}
+ \value StyleReader.Pane \l {Pane}
+ \value StyleReader.Popup \l {Popup}
+ \value StyleReader.ProgressBar \l {ProgressBar}
+ \value StyleReader.RadioButton \l {RadioButton}
+ \value StyleReader.RadioDelegate \l {RadioDelegate}
+ \value StyleReader.RoundButton \l {RoundButton}
+ \value StyleReader.ScrollBar \l {ScrollBar}
+ \value StyleReader.ScrollView \l {ScrollView}
+ \value StyleReader.SearchField \l {SearchField}
+ \value StyleReader.Slider \l {Slider}
+ \value StyleReader.SpinBox \l {SpinBox}
+ \value StyleReader.SwipeDelegate \l {SwipeDelegate}
+ \value StyleReader.Switch \l {Switch}
+ \value StyleReader.SwitchDelegate \l {SwitchDelegate}
+ \value StyleReader.TabBar \l {TabBar}
+ \value StyleReader.TabButton \l {TabButton}
+ \value StyleReader.TableViewDelegate \l {TableViewDelegate}
+ \value StyleReader.TextArea \l {TextArea}
+ \value StyleReader.TextField \l {TextField}
+ \value StyleReader.ToolBar \l {ToolBar}
+ \value StyleReader.ToolButton \l {ToolButton}
+ \value StyleReader.ToolSeparator \l {ToolSeparator}
+ \value StyleReader.ToolTip \l {ToolTip}
+ \value StyleReader.Tumbler \l {Tumbler}
\sa {StyleVariation::controlType}{StyleVariation.controlType}
*/
diff --git a/src/labs/stylekit/qqstylekitreader_p.h b/src/labs/stylekit/qqstylekitreader_p.h
index d12c887ebf..e022c99f06 100644
--- a/src/labs/stylekit/qqstylekitreader_p.h
+++ b/src/labs/stylekit/qqstylekitreader_p.h
@@ -78,6 +78,7 @@ public:
SearchField,
TabBar,
TabButton,
+ TableViewDelegate,
TextArea,
TextField,
TextInput,
diff --git a/src/labs/stylekit/qqstylekittheme.cpp b/src/labs/stylekit/qqstylekittheme.cpp
index 6edb8de25c..cda990299a 100644
--- a/src/labs/stylekit/qqstylekittheme.cpp
+++ b/src/labs/stylekit/qqstylekittheme.cpp
@@ -68,6 +68,7 @@ static QQuickTheme::Scope scopeForType(QQStyleKitExtendableControlType type)
case QQStyleKitReader::ControlType::GroupBox:
return QQuickTheme::GroupBox;
case QQStyleKitReader::ControlType::ItemDelegate:
+ case QQStyleKitReader::ControlType::TableViewDelegate:
return QQuickTheme::ItemView;
case QQStyleKitReader::ControlType::Label:
return QQuickTheme::Label;