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. formatting list items for width

formatting list items for width

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 2 Posters 493 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #1

    Hi all -

    I have a QML display that looks like this:
    loadsamplesheet2.PNG

    I'd like to give the name column some extra space, taking it from the source and synthesis date columns. The QML file is a bit of a mystery to me, though. I've pared it down to the essentials (I hope) for inclusion here:

        //Viewmodel needs to give data on a row by row basis
        delegate: Component {
          id: dataDelegate
    
          Row {
            id: data
    
            // we must store the DELEGATE index before it gets shadowed by Repeater index!
            property int delegateIdx: index
    
            function getRowData(updaterHack, index) {
              return viewModel.rowData(index)
            }
    
            Repeater {
              model: currentData.length + extraCols_
              Rectangle {
                width: cellWidth
                height: cellHeight
    
                Text {
                  visible: index < currentData.length
                  text: {
                    if (index < currentData.length) {
                      currentData[index]
                    } else {
                      ""
                    }
                  }
    
                  anchors.verticalCenter: parent.verticalCenter
                  anchors.horizontalCenter: parent.horizontalCenter
    

    So, I see where the entire row is formatted, but how do I go about formatting the elements within the repeater?

    I'm sure I've left out a lot of important information, so please...ask away!

    Thanks...

    1 Reply Last reply
    0
    • mzimmersM Offline
      mzimmersM Offline
      mzimmers
      wrote on last edited by
      #2

      Well, I've made some progress. Using:

        property int cellWidth: width / (viewModel.header().length + extraCols_)
        property variant columnWidths: [cellWidth * 2, cellWidth / 3, cellWidth * 2 / 3, cellWidth]
      ...
              Repeater {
                // passing in the 'throwaway' updater is a hack to ensure that the view updates
                model: currentData.length + extraCols_
                Rectangle {
                    width: if (index < currentData.length) {
                               columnWidths[index]
                           } else {
                               cellWidth
                           }
      

      I now can control the allocated widths for the columns. (I realize this is a hack, but I'm more technician than developer on this project.)

      For some reason, I can't apply this to the header, though:

              Repeater {
                id: headerRow
      
                Button {
                  id: headerButton
      
                  background: Rectangle {
                    id: headerRect
      
                    Text {
                      id: textbox
                      width: columnWidths[index]
      

      Produces this:

      sample.PNG

      Any ideas on how to fix this would be appreciated...thanks.

      1 Reply Last reply
      0
      • fcarneyF Offline
        fcarneyF Offline
        fcarney
        wrote on last edited by
        #3

        You might have to qualify the name of the object that holds columnWidths:

        object.columnWidths[index]
        

        Is it giving any errors on columnWidths?

        C++ is a perfectly valid school of magic.

        mzimmersM 1 Reply Last reply
        0
        • fcarneyF fcarney

          You might have to qualify the name of the object that holds columnWidths:

          object.columnWidths[index]
          

          Is it giving any errors on columnWidths?

          mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #4

          @fcarney I didn't have to qualify my array for the repeating rows:

          Item {
            id: root
            property variant columnWidths: [cellWidth * 2, cellWidth / 3, cellWidth * 2 / 3, cellWidth]
            ListView {
              id: table
              width: parent.width
          
              Component {
                id: headerDelegate
                Row {
                  id: headers
                  Repeater {
                    id: headerRow
          
                    Button {
                      width: cellWidth
                      background: Rectangle {
          
                        Text {
                          id: textbox
                          width: columnWidths[index] // doesn't work here.
          
              delegate: Component {
                id: dataDelegate
          
                Row {
                  Repeater {
                    Rectangle {
                        width: columnWidths[index] // works here.
          

          As far as errors...that's something else I'm having problems with. I simply cannot get any console.log output to display. That makes debugging this stuff even more difficult.

          1 Reply Last reply
          0
          • mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by mzimmers
            #5

            I should mention: when I don't apply a width setting to my header elements, the screen looks like this:
            sample.PNG

            I'd like "Source" to be over the I/U column, and "Synthesis Date" to be moved over a bit.

            1 Reply Last reply
            0
            • mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #6

              Found the problem: the width formatting needed to be applied at the Button level, not at the Text level:

                      Repeater {
                        id: headerRow
                        model: currentHeaders.length + extraCols_
                        Button {
                          id: headerButton
                          width: columnWidths[index]
                          ...
              
              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