I've created TableView component as below and instantiate it several times. I want to handle mouse events for header/table cells. Problem is that only last instance gets these events. I've played this for hours with propagateComposedEvents/preventStealing/mouse.accepted and many others but without any success (tried qt6.5.1 / 6.5.2). Any idea why is this happening? Do you see the same behavior?
import QtQuick 6.5
import QtQuick.Controls 6.5
import QtQuick.Layouts 6.5
import Qt.labs.qmlmodels 1.0
ApplicationWindow {
visible: true
id: app
width: 1280
height: 800
Component {
id: testTable
Rectangle {
id: control
implicitHeight: 200
implicitWidth: 400
Component.onCompleted: {
// just fill a table with some data
tableView.model.appendRow({ value : 10 })
tableView.model.appendRow({ value : 20 })
tableView.model.appendRow({ value : 30 })
}
ColumnLayout { // Header + TableView
id: contentLayout
anchors.fill: parent
HorizontalHeaderView {
id: horizontalHeader
Layout.fillWidth: true
syncView: tableView
model: [
qsTr("Value")
]
delegate: Rectangle {
border.width: 1
implicitHeight: 20
implicitWidth: 50
MouseArea {
anchors.fill: parent
onClicked: (mouse) => {
print("Header onClicked")
}
onPressed: (mouse) => {
print("Header onPressed")
}
onReleased: (mouse) => {
print("Header onReleased")
}
}
Text {
text: modelData
anchors.centerIn: parent
}
}
}
TableView {
id: tableView
Layout.fillWidth: true
Layout.fillHeight: true
model: TableModel {
TableModelColumn {
display: "value"
}
}
delegate: Rectangle {
border.width: 1
implicitHeight: 20
implicitWidth: 50
MouseArea {
anchors.fill: parent
onClicked: (mouse) => {
print("Table onClicked")
}
onPressed: (mouse) => {
print("Table onPressed")
}
onReleased: (mouse) => {
print("Table onReleased")
}
}
Text {
anchors.centerIn: parent
text: model.display
}
}
}
}
}
}
Column {
Loader {
sourceComponent: testTable
}
Loader {
sourceComponent: testTable
}
Loader { // only the last 'testTable' gets mouse events, why???
sourceComponent: testTable
}
}
}
I also tried to put the table component in separated file and use simple layout instead of Loader: the result was the same.