TableView with CheckBox in header
Solved
QML and Qt Quick
-
Hi,
i have a QML TableView and would like to put a checkbox in the header row.
Therefore i added a checkbox to the headerDelegate, but if i click on it, it does not change its state. Its always 'checked'.Has anyone an idea why i can not click on the checkbox.
I also tried to a add a MouseArea to the header but it seems it will be ignored as well.My code looks like:
TableView { id: tableView height: parent.height width: parent.width/2 ... headerDelegate: Item { height: 20 anchors.left: parent.left anchors.right: parent.right CheckBox { anchors.centerIn: parent id: activateAllEvents checked: true visible: styleData.column === 4 // Show only in the 4th column activeFocusOnPress: true text: "" } } }
-
@medyakovvit No there are no signals emitted.
I tried
onClicked: { console.log("onClick"); } onPressedChanged: { console.log("onPressedChanged"); } onCheckedChanged: { console.log("onCheckedChanged"); }
but none of the functions are called if i click on the checkbox.
-
@PhTe, workaround:
headerDelegate: Item { height: 20 anchors.left: parent.left anchors.right: parent.right CheckBox { id: activateAllEvents anchors.centerIn: parent property bool myPressed: styleData.pressed checked: true visible: styleData.column === 4 // Show only in the 4th column activeFocusOnPress: true text: "" onMyPressedChaged: { if(myPressed) checked = !checked; } } }
-
@medyakovvit Yeah, that woks. Thanks :)