Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Delegate not aligning Child without Anchors
Qt 6.11 is out! See what's new in the release blog

Delegate not aligning Child without Anchors

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SocketSackett
    wrote on last edited by SocketSackett
    #1

    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
    
    jeremy_kJ 1 Reply Last reply
    0
    • S Offline
      S Offline
      SocketSackett
      wrote on last edited by
      #2

      @SocketSackett

      I tried changing to a CheckDelegate of Qt Quick 2, but it overdraws the Header as well.

      1 Reply Last reply
      0
      • S SocketSackett

        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
        
        jeremy_kJ Offline
        jeremy_kJ Offline
        jeremy_k
        wrote on last edited by
        #3

        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.

        Asking a question about code? http://eel.is/iso-c++/testcase/

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SocketSackett
          wrote on last edited by SocketSackett
          #4

          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]

          2d699625-fbe4-418a-9022-d04c4cf98e4f-image.png

          jeremy_kJ 1 Reply Last reply
          0
          • S SocketSackett

            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]

            2d699625-fbe4-418a-9022-d04c4cf98e4f-image.png

            jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on last edited by
            #5

            Did you try making the HorizontalHeaderView a sibling of the TableView, as in this example?

            Asking a question about code? http://eel.is/iso-c++/testcase/

            S 1 Reply Last reply
            0
            • jeremy_kJ jeremy_k

              Did you try making the HorizontalHeaderView a sibling of the TableView, as in this example?

              S Offline
              S Offline
              SocketSackett
              wrote on last edited by
              #6

              @jeremy_k Yes. It is a sibling. Above you can see it is below the scrollbars of the TableView.

              jeremy_kJ 1 Reply Last reply
              0
              • S SocketSackett

                @jeremy_k Yes. It is a sibling. Above you can see it is below the scrollbars of the TableView.

                jeremy_kJ Offline
                jeremy_kJ Offline
                jeremy_k
                wrote on last edited by
                #7

                @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.

                Asking a question about code? http://eel.is/iso-c++/testcase/

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved