Results 1 to 2 of 2

Thread: Heterogenous columns in QTreeView

  1. #1
    Join Date
    Sep 2009
    Location
    San Antonio, Texas
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Heterogenous columns in QTreeView

    I have a heirarchical model which has different numbers of columns per teir, but I haven't figured out a way to get QTreeView to show the maximum number of columns without faking the maximum at the root level.

    This is essentially what my columnCount looks like:

    Qt Code:
    1. //Returns the number of columns for the children of the given parent
    2. int Model::columnCount(const QModelIndex &index) const {
    3. if( index.isValid() )
    4. return 6;
    5. return 1;
    6. }
    To copy to clipboard, switch view to plain text mode 

    Initially the model is empty - so the table has 1 column and no rows.

    I am resetting the model after adding data, which populates the TreeView with 1 first-tier entry and a few hundred second-tier entries, but the TreeView is still fixed at 1 column.
    While its possible to do per-entry beginInsertRows/endInsertRows and beginInsertColumns/endInsertColumns, I don't know if this would help - and it would be complex due to the nature of the data.

    Now if I changed the columnCount to always return 6 - then the table shows all the columns all the time, but I think this is really a hack - the 1st tier items don't have valid indices for columns 1-5.

    Any suggestions?

    Justin

  2. #2
    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: Heterogenous columns in QTreeView

    Return column count of 6 and use QTreeView::setFirstColumnSpanned. It's still a hack though.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    rain87 (21st November 2012)

Similar Threads

  1. One Model, Two Views (QTreeView and QTableView)
    By dgarrett97 in forum Newbie
    Replies: 2
    Last Post: 14th September 2009, 18:10
  2. AutoAdjust columns in a QTreeView
    By alexandernst in forum Newbie
    Replies: 4
    Last Post: 27th July 2009, 10:51
  3. Moving columns/hiding columns in QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2007, 16:22
  4. [qt4 & Xp] resize columns of a QTreeView
    By incapacitant in forum Newbie
    Replies: 4
    Last Post: 2nd March 2006, 14:06
  5. Changing the order of columns in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 00:00

Tags for this Thread

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.