[vlc-commits] [Git][videolan/vlc][master] qml: fix binding issues in table view with Qt 6.4
Steve Lhomme (@robUx4)
gitlab at videolan.org
Mon Nov 17 02:38:49 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
6c1172c8 by Pierre Lamot at 2025-11-17T02:23:28+00:00
qml: fix binding issues in table view with Qt 6.4
passing binding to object to createObject fails with Qt6.4, see QTBUG-125095.
Using `var` properties as suggested in the Qt bug report isn't enough to
workaround the issue.
The proposed approach is to create a local QtObject containing the bindings and
pass it in the delegate creation (without binding), then we create readonly
properties to the model properties for convenience
fix: #29430
- - - - -
4 changed files:
- modules/gui/qt/widgets/qml/TableHeaderDelegate.qml
- modules/gui/qt/widgets/qml/TableRowDelegate.qml
- modules/gui/qt/widgets/qml/TableViewDelegateExt.qml
- modules/gui/qt/widgets/qml/TableViewExt.qml
Changes:
=====================================
modules/gui/qt/widgets/qml/TableHeaderDelegate.qml
=====================================
@@ -16,12 +16,24 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
import QtQuick
+import VLC.Style
+// FIXME: Qt 6.4
+// using QObject/QGadget types in Qt.binding in createObject fails
+// see https://bugreports.qt.io/browse/QTBUG-125095
+// even typing as var seems to be broken with 6.4, so instead we
+// create a local CellModel object that contains the bindings and pass
+// it (without bindings) to createObject
Item {
- required property var colModel
+ required property CellModel cellModel
+
+ //we can't use `alias` to reference onything else than a child's property
+ readonly property var colModel: cellModel.colModel
+ readonly property ColorContext colorContext: cellModel.colorContext
+
+ component CellModel: QtObject {
+ required property var colModel
+ required property ColorContext colorContext
+ }
- // using QObject/QGadget types in Qt.binding fails
- // so don't mark 'ColorContext' type here
- // see https://bugreports.qt.io/browse/QTBUG-125095
- required property var colorContext
}
=====================================
modules/gui/qt/widgets/qml/TableRowDelegate.qml
=====================================
@@ -16,19 +16,40 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
import QtQuick
+import VLC.Style
+// FIXME: Qt 6.4
+// using QObject/QGadget types in Qt.binding in createObject fails
+// see https://bugreports.qt.io/browse/QTBUG-125095
+// even typing as var seems to be broken with 6.4, so instead we
+// create a local CellModel object that contains the bindings and pass
+// it (without bindings) to createObject
Item {
- required property int index
- required property var colModel
- required property var rowModel
- required property bool selected
- required property bool containsMouse
- required property bool currentlyFocused
-
- // using QObject/QGadget types in Qt.binding fails
- // so don't mark 'ColorContext' type here
- // see https://bugreports.qt.io/browse/QTBUG-125095
- required property var colorContext
-
- required property Item delegate
+ required property CellModel cellModel
+
+ //we can't use `alias` to reference onything else than a child's property
+ readonly property int index: cellModel.index
+ readonly property var colModel: cellModel.colModel
+ readonly property var rowModel: cellModel.rowModel
+ readonly property int selected: cellModel.selected
+ readonly property bool containsMouse: cellModel.containsMouse
+ readonly property bool currentlyFocused: cellModel.currentlyFocused
+ readonly property ColorContext colorContext: cellModel.colorContext
+ readonly property Item delegate: cellModel.delegateItem
+
+
+ component CellModel: QtObject {
+ required property int index
+ required property var colModel
+ required property var rowModel
+ required property bool selected
+ required property bool containsMouse
+ required property bool currentlyFocused
+
+
+ required property ColorContext colorContext
+
+ required property Item delegateItem
+
+ }
}
=====================================
modules/gui/qt/widgets/qml/TableViewDelegateExt.qml
=====================================
@@ -236,19 +236,24 @@ T.Control {
}
height: parent.height
+ TableRowDelegate.CellModel {
+ id: cellModel
+ rowModel: delegate.rowModel
+ colModel: loader.modelData.model
+ index: delegate.index
+ currentlyFocused: delegate.visualFocus
+ selected: delegate.selected
+ containsMouse: delegate.hovered
+ colorContext: theme
+ delegateItem: delegate
+ }
+
Component.onCompleted: {
const del = modelData.model.colDelegate || delegate.defaultDelegate
item = del.createObject(loader, {
+ cellModel: cellModel,
width: Qt.binding(() => loader.width),
height: Qt.binding(() => loader.height),
- rowModel: Qt.binding(() => delegate.rowModel),
- colModel: Qt.binding(() => loader.modelData.model),
- index: Qt.binding(() => delegate.index),
- currentlyFocused: Qt.binding(() => delegate.visualFocus),
- selected: Qt.binding(() => delegate.selected),
- containsMouse: Qt.binding(() => delegate.hovered),
- colorContext: Qt.binding(() => theme),
- delegate: delegate
}
)
if (item.artworkTextureProvider) {
=====================================
modules/gui/qt/widgets/qml/TableViewExt.qml
=====================================
@@ -353,6 +353,12 @@ FocusScope {
required property var modelData
property TableHeaderDelegate _item: null
+ TableHeaderDelegate.CellModel {
+ id: cellModel
+ colorContext: view.colorContext
+ colModel: modelData.model
+ }
+
height: VLCStyle.tableHeaderText_height
width: {
if (!!modelData.size)
@@ -371,8 +377,7 @@ FocusScope {
headerCell._item = comp.createObject(headerCell, {
width: Qt.binding(() => headerCell.width),
height: Qt.binding(() => headerCell.height),
- colorContext: Qt.binding(() => view.colorContext),
- colModel: Qt.binding(() => modelData.model)
+ cellModel: cellModel,
})
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6c1172c8ee98ab8713b780f2ffc5e1dacb8a0e88
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6c1172c8ee98ab8713b780f2ffc5e1dacb8a0e88
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list