Results 1 to 2 of 2

Thread: Changing the order of columns in QTreeView

  1. #1
    Join Date
    Feb 2006
    Posts
    47
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Changing the order of columns in QTreeView

    Hello,

    I was just wondering how to change the order of columns as they appear in QTreeView when using QDirModel. Here is a snippet of code:

    Qt Code:
    1. // Declare the new objects.
    2. Directory_Model = new QDirModel;
    3. File_Path = new QString;
    4.  
    5. // Set the file system structure parameters.
    6. Directory_Model->setFilter(QDir::AllDirs);
    7. Directory_Model->setSorting(QDir::Time);
    8.  
    9. // Set the tree model (visual) parameters.
    10. this->QTreeView::setModel(Directory_Model);
    11. this->setColumnHidden(1,1);
    12. this->setColumnHidden(2,1);
    13. //this->setColumnHidden(3,1); //This crashes the widget. Why does this happen?
    To copy to clipboard, switch view to plain text mode 

    As it stands, I can see the directory tree, and then the modification time - in that order from left to right. I want this order reversed... how can this be done?

    JS.

  2. #2
    Join Date
    Jan 2006
    Posts
    22
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Changing the order of columns in QTreeView

    this->QTreeView::setModel(Directory_Model);
    this->setColumnHidden(1,1);
    this->setColumnHidden(2,1);
    //this->setColumnHidden(3,1); //This crashes the widget. Why does this happen?
    This seems to happen because the dir model has no column with index 3 (and Qt does not check itself). You should use columnCount() to check if your index is valid.

    Anyway - you want change the order:
    I was just wondering how to change the order of columns as they appear in QTreeView when using QDirModel. Here is a snippet of code
    But you do hide a column
    Maybe this works (did not test it):
    Qt Code:
    1. this->header().moveSection( 0, 1 );
    To copy to clipboard, switch view to plain text mode 
    As I assume you are inside the constructor (or any other method of your tree class) you could also omit the this->

Similar Threads

  1. QTreeView: get current sort column and order
    By supergillis in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2008, 17:25
  2. Changing column order in QTableView
    By Banjo in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2008, 06:49
  3. Saving/Restoring columns order of QTreeWidget
    By mchara in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 08:43
  4. Moving columns/hiding columns in QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2007, 16:22
  5. Changing the text color of a QTreeView leaf.
    By johnny_sparx in forum Qt Programming
    Replies: 3
    Last Post: 22nd March 2006, 23:58

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.