Results 1 to 5 of 5

Thread: [qt4 & Xp] resize columns of a QTreeView

  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Red face [QT4 & XP] resize columns of a QTreeView

    I have this QtreeView 'table' based on a QStandardItemModel 'model'.

    Qt Code:
    1. model->setHeaderData(0, Qt::Horizontal, tr("Mois"));
    2. model->setHeaderData(1, Qt::Horizontal, tr("Facture"));
    To copy to clipboard, switch view to plain text mode 
    I found how I can set the header text, but not how I can resize the columns.
    No member in QTreeView does that. And the model should not be involved I guess.
    resizeColumnTo Contents does not help me.

    So I don't know how I can resize my columns in the view !!
    Last edited by incapacitant; 2nd March 2006 at 13:40. Reason: better title

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: [qt4 & Xp] resize columns of a QTreeView

    Quote Originally Posted by incapacitant
    So I don't know how I can resize my columns in the view !!
    You can access the header view by QTreeView::header().
    QHeaderView offers you a couple of methods for resizing 'sections'.

  3. The following user says thank you to jpn for this useful post:

    incapacitant (2nd March 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: [qt4 & Xp] resize columns of a QTreeView

    You should access the header (using view's header() method) which is of QHeaderView type. There are some ways to access header sizes there.

  5. The following user says thank you to wysota for this useful post:

    incapacitant (2nd March 2006)

  6. #4
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: [qt4 & Xp] resize columns of a QTreeView

    I had seen this possibility as the doc points to it, but I can't get my syntax right :

    Qt Code:
    1. table->setHeader(QHeaderView::resizeSection(0,100));
    To copy to clipboard, switch view to plain text mode 


    compile error:
    cannot call member function `void QHeaderView::resizeSection(int, int)' without object


    I tried several combination but I can't get the QTreeView table linked to QHeaderView...

  7. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: [qt4 & Xp] resize columns of a QTreeView

    Qt Code:
    1. table->header()->resizeSection(0,100);
    To copy to clipboard, switch view to plain text mode 

  8. The following user says thank you to jpn for this useful post:

    incapacitant (2nd March 2006)

Similar Threads

  1. Don't resize columns - QTableView
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 26th January 2009, 16:59
  2. Moving columns/hiding columns in QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2007, 16:22
  3. Resize QTreeWidget columns to contents
    By FaS in forum Qt Programming
    Replies: 9
    Last Post: 2nd July 2006, 20:48
  4. [QT4 & XP] QTreeView issue with Designer form
    By incapacitant in forum Newbie
    Replies: 3
    Last Post: 2nd March 2006, 17:42
  5. Changing the order of columns in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 00:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.