Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get width of a column in Qtreeview if I have column Name
Forum Updated to NodeBB v4.3 + New Features

How to get width of a column in Qtreeview if I have column Name

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.4k Views 2 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by
    #1

    I have columName , How to get width of a column in Qtreeview ?

    For example if the Qtreeview has

    A B C D as columns

    I have B how to get the width of B

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      What about
      int width = ui->treeView->columnWidth( index );

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        how to get index from columnName

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          Normally you would get that from a ModelIndex when you click something etc.
          I don't think there is search by name.
          You can loop them like

          QStringList headers;
              for (int i = 0; i < ui->treeView->model()->columnCount(); i++) {
                  headers.append(ui->treeView->model()->headerData(i, Qt::Horizontal).toString());
              }
          
          1 Reply Last reply
          1

          • Login

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