Delegate not aligning Child without Anchors
-
Hi, I have the following TableView below. I am not getting the cell in the delegate to align without an anchor. Under Quick 2 this doesn't work the way it used to. There is an error of "TableView: anchors detected. Use implicitWidth & implicityHeight. I added both implicit dimensions & it overlays the header. How is this handled with a CheckBox delegate so that it lines up properly? Is there a workaround or a better way to do this in Quick 2?
TableView { id: tblFooParams height: parent.height width: parent.width anchors.fill: parent columnSpacing: 1 rowSpacing: 1 ScrollBar.vertical: ScrollBar { id: tblFooParamsVertBar; active: tblFooParamsVertBar.active policy:ScrollBar.AlwaysOn } ScrollBar.horizontal: ScrollBar { id: tblFooParamsHorzBar; active: tblFooParamsHorzBar.active } HorizontalHeaderView { id: hdrFooParams syncView: tblFooParams model: ["Col1", "Col2", "Col3", "Col4", "Col5", "Col6" ] anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top anchors.leftMargin: 1 } model: TableModel { id: modelFooParams TableModelColumn { display: "col1" } TableModelColumn { display: "col2" } TableModelColumn { display: "col3" } TableModelColumn { display: "col4" } TableModelColumn { display: "col5" } TableModelColumn { display: "col6" } rows: [ { "col1": "true", "col2": "true", "col3": "true", "col4": "true", "col5: "true", "col6: "true" } ] } delegate: CheckBox { id: cellFooEnabled implicitWidth: 50 implicitHeight: 20 checked: false // anchors.baseline: parent.verticalCenter checkState: Qt.Checked nextCheckState: function() { if (checkState === Qt.Checked) return Qt.Unchecked else return Qt.Checked } } } // end Foo TableView
-
I tried changing to a CheckDelegate of Qt Quick 2, but it overdraws the Header as well.
-
Hi,
The posted code without the import statements is ambiguous. It isn't clear which TableView or CheckBox is intended.
@SocketSackett said in Delegate not aligning Child without Anchors:
Hi, I have the following TableView below. I am not getting the cell in the delegate to align without an anchor.
What is the cell intended to align with? It may help to include a picture of what is happening now, and another showing the goal.
Under Quick 2 this doesn't work the way it used to. There is an error of "TableView: anchors detected. Use implicitWidth & implicityHeight.
Don't anchor the delegate. The view manages its placement.
I added both implicit dimensions & it overlays the header. How is this handled with a CheckBox delegate so that it lines up properly? Is there a workaround or a better way to do this in Quick 2?
The problem is that the code above is placing the HorizontalHeaderView as a child of the TableView. Instead, use it as a sibling.
TableView { id: tblFooParams height: parent.height width: parent.width anchors.fill: parent
There's no point in specifying height + width and anchors.fill.
delegate: CheckBox { id: cellFooEnabled width: Math.abs(implicitWidth) height: Math.abs(implicitHeight)
If width and height aren't specified, the implicit versions are used. There's no need to do this explicitly.
-
It is intended to sync with the Header. I've done this many times with Text, but once I use CheckDelegate, it doesn't work. If I leave out the anchors. The check boxes overwrite the header! That's the issue. TableView works fine with Text. I set implicitWidth: 50; implicitHeight: 20, but it still overwrites the header with the checkboxes.![alt text]
-
@SocketSackett said in Delegate not aligning Child without Anchors:
@jeremy_k Yes. It is a sibling. Above you can see it is below the scrollbars of the TableView.
I don't see any scrollbars.
In the initial post, the HorizontalHeaderView is a child of the TableView. If that has been changed and it still doesn't work, post the updated code.