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. HorizontalHeaderView ColumnWidthProvider confusion
Forum Updated to NodeBB v4.3 + New Features

HorizontalHeaderView ColumnWidthProvider confusion

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 310 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #1

    According to the documentation
    ColumnWidthProvider This property can hold a function that returns the column width for each column in the model

    Based on the above documentation, I did the following.
    Code snippet below.

    Not Working - I defined method called columnWidth & gave method name. This did not work.

    Working - If I define method directly with property value, then it works. e.g uncomment the following commented code & comment another line.

    Window {
       id : root
      function columnWidth(column) {
            console.log(" Value...."+column)
            return 50
        }
    
        HorizontalHeaderView {
            id: horizontalHeader
            width: parent.width
            height: 100
            // columnWidthProvider: function(column){
            //        return 50;
            //    }
            columnWidthProvider : root.columnWidth(column)
          }
    }
    

    My conclusion -
    So defining function & passing as value will NOT work. It is necessary that method has to inline.

    Is this assumption true ? Anything missing from my side ?

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

    GrecKoG 1 Reply Last reply
    0
    • A Offline
      A Offline
      afalsa
      wrote on last edited by
      #2

      Hello again!

      You should inject the column parameter before calling the function

      import QtQuick
      import QtQuick.Controls
      
      Window {
          id: root
          function columnWidth(column) {
              if (!horizontalHeader.isColumnLoaded(column))
                  return -1
      
              console.log(" Value...." + column)
              return 50
          }
      
          HorizontalHeaderView {
              id: horizontalHeader
              width: parent.width
              height: 100
              model: 3
              columnWidthProvider: column => root.columnWidth(column)
          }
      }
      
      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        Thanks @afalsa. Yes need to inject the parameter. Documentation is not clear about this. Additional information like this will help.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        1
        • dheerendraD dheerendra

          According to the documentation
          ColumnWidthProvider This property can hold a function that returns the column width for each column in the model

          Based on the above documentation, I did the following.
          Code snippet below.

          Not Working - I defined method called columnWidth & gave method name. This did not work.

          Working - If I define method directly with property value, then it works. e.g uncomment the following commented code & comment another line.

          Window {
             id : root
            function columnWidth(column) {
                  console.log(" Value...."+column)
                  return 50
              }
          
              HorizontalHeaderView {
                  id: horizontalHeader
                  width: parent.width
                  height: 100
                  // columnWidthProvider: function(column){
                  //        return 50;
                  //    }
                  columnWidthProvider : root.columnWidth(column)
                }
          }
          

          My conclusion -
          So defining function & passing as value will NOT work. It is necessary that method has to inline.

          Is this assumption true ? Anything missing from my side ?

          GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          @dheerendra said in HorizontalHeaderView ColumnWidthProvider confusion:

          ColumnWidthProvider This property can hold a function that returns the column width for each column in the model
          Based on the above documentation, I did the following:
          [...]
          columnWidthProvider: root.columnWidth(column)

          When you are doing this you are not passing a function to the columnWidthProvider. This code instead tries to execute the root.colummWidth function by passing column as the parameter (most likely undefined here and pass the return value to columnWidthProvider. Did this produces a warning?

          What you wanted to do is:
          columnWidthProvider: root.columnWidth (or what afalsa wrote).

          I agree that an example or 2 in the documentation won't hurt.

          1 Reply Last reply
          1
          • dheerendraD dheerendra has marked this topic as solved on

          • Login

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