PDA

View Full Version : Changing the order of columns in QTreeView



johnny_sparx
14th February 2006, 19:07
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:


// Declare the new objects.
Directory_Model = new QDirModel;
File_Path = new QString;

// Set the file system structure parameters.
Directory_Model->setFilter(QDir::AllDirs);
Directory_Model->setSorting(QDir::Time);

// Set the tree model (visual) parameters.
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?

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.

orb9
15th February 2006, 00:00
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):


this->header().moveSection( 0, 1 );

As I assume you are inside the constructor (or any other method of your tree class) you could also omit the this->