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:
Code:
// Declare the new objects.
// 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.
Re: Changing the order of columns in QTreeView
Quote:
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:
Quote:
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):
Code:
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->