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. TreeView Model: Resize header column
QtWS25 Last Chance

TreeView Model: Resize header column

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.5k Views
  • 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.
  • M Offline
    M Offline
    MisteKiste
    wrote on last edited by
    #1

    Hey Guys,

    I have got a treeview (+model) with a two column header. Now the width from the first row have to be larger than the second. But I don't know how to implement it.

    I just can resize the height of both rows.
    In headerData Methode:
    @ if(role == Qt::SizeHintRole)
    {
    return QSize(30, 30);
    }@

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Try "resizeSection":http://qt-project.org/doc/qt-5/qheaderview.html#resizeSection. You could access it using header() of QTreeView.

      157

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chrisaverage
        wrote on last edited by
        #3

        A two row header? It would mean the header is vertical but treeviews don't have those. In any case rows have always the same width but can differ in height. Did you maybe mean a column?

        In headerData() you get the first parameter that indicates which header section it is. You can differentiate on that eg.
        @
        switch(section) {
        default: return /something/;
        case 0: return /something else/;
        case 1: return /something else entirely/;
        }
        @

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MisteKiste
          wrote on last edited by
          #4

          Ohhh, yes of course i mean coloumn instead of row, sry -.-'. I edited it in main post.

          [at ]p3c0
          But I can't access the view from my model or how can I call resizeSection?

          [at] chrisaverage

          I tried this:
          @ if(role == Qt::SizeHintRole)
          {
          switch(section) {
          case 0: return QSize(70, 30);
          case 1: return QSize(30, 30);
          }
          }@

          But it doesn't work. When I change both height values from 30 to for example 20, the height goes smaller. So I think return a QSize works, but only for height not for witdh. :(

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MisteKiste
            wrote on last edited by
            #5

            Mhm has nobody an idea? :(

            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