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. How align Listview's delegate text to customized title text?

How align Listview's delegate text to customized title text?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 488 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.
  • Crawl.WC Offline
    Crawl.WC Offline
    Crawl.W
    wrote on last edited by Crawl.W
    #1
    import QtQuick 2.0
    
    Item
    {
        id: root
        width: 1921
        height: 1081
    
        Column
        {
            x: 328
            y: 184
            Item
            {
                id: tableTitle
                width: 1593
                height: 91
                Text {
                    id: ttWellId
                    x: 90
                    y: 31
                    text: "Well ID"
                }
                Text {
                    id: ttSample
                    x: 276
                    y: 31
                    text: "Sample"
                }
            }
    
            ListView
            {
                width: 1593
                height: 785
                clip: true
                model: ListModel {
                    ListElement{
                        name: "A1";
                        sample: "sample1";
                    }
                    ListElement{
                        name: "A2";
                        sample: "sample2";
                    }
                }
                delegate: resultDelegate
    
                Component
                {
                    id: resultDelegate
                    Item
                    {
                        id: wellInfoItem
                        height: 60
                        width: 1592
                        Text
                        {
                            text: name
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.horizontalCenter: ttWellId.horizontalCenter
                        }
                        Text {
                            text: sample
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.horizontalCenter: ttWellId.horizontalCenter
                        }
                    }
                }
            }
        }
    }
    

    I need resultDelegate's text align to text in the tableTitle. But anchors.horizontalCenter: ttWellId.horizontalCenter's effect as following:
    4daa9cc6-ced7-499f-9a66-a1b0d32a3e16-image.png
    The effect I want is as follows :
    de39afaf-448d-4646-8a14-c211a655ae23-image.png
    please ignore the multiple row and focus on contents are aligned horizontally to the header. And I got a error hint: QML Text: Cannot anchor to an item that isn't a parent or sibling.

    1 Reply Last reply
    0
    • Crawl.WC Offline
      Crawl.WC Offline
      Crawl.W
      wrote on last edited by
      #2

      I have a solution, aligning field to header title and setting the same width, then we could set same alignment for Text item.
      But my .qml file from Qt Designer Stutido, They had been given in the form of fixed coordinates at most of the time, adjusting for my solution is too terrible.

      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