TreeView Model: Resize header column



  • 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);
    }@


  • Moderators

    Hi,

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



  • 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/;
    }
    @



  • 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. :(



  • Mhm has nobody an idea? :(


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.