PDA

View Full Version : Moving columns/hiding columns in QTreeView



yogeshm02
14th March 2007, 14:32
I have an QAbstractItemModel implementation which exposes a tree like structure. I'm using standard QTreeView to display its data. Now, I want to let the user have an option to show/hide and move columns in any manner. The problem is if first column is hidden, decoration of tree (i.e. +s & -s to expand or otherwise the data) is also not shown, and when first column is moved, decoration of tree moves along.
What should I do:confused:

fullmetalcoder
14th March 2007, 14:44
What should I do:confused:
Well, you should start by being a little more precise... :rolleyes: What exactly do you mean by hiding and moving? When should these occur? What kind of data do you show? ...
You may also consider showing us your reimplementation of QAbstractItemModel...

yogeshm02
14th March 2007, 15:18
What exactly do you mean by hiding and moving? When should these occur? What kind of data do you show? ...
You may also consider showing us your reimplementation of QAbstractItemModel...
hide -> hide any column of the view
mode-> mode any column of the view to change its position

data is a simple list of items which are grouped together much like a directory structure.

fullmetalcoder
14th March 2007, 15:49
hide -> hide any column of the view
mode-> mode any column of the view to change its position

data is a simple list of items which are grouped together much like a directory structure.
There is no helper for this, you'll have to implement this on your own. I suggest you perform this at model level by keeping a record of columns state (shown or hidden), possibly through a QSet<bool> whoses indexes would correspond to columns. Then you should return a columnCount() according to the number of hidden columns and finally you should make sure that hidden columns do not mess up the data by modifying the data() setData() functions. :)It should not be too hard but, as you pointed out, there is one limitation : the first column should not be hidden (unless the way you store hierarchy allows it...). If you still have problems you should send some code...

yogeshm02
14th March 2007, 16:22
There is no helper for this, you'll have to implement this on your own. I suggest you perform this at model level by keeping a record of columns state (shown or hidden), possibly through a QSet<bool> whoses indexes would correspond to columns. Then you should return a columnCount() according to the number of hidden columns and finally you should make sure that hidden columns do not mess up the data by modifying the data() setData() functions. :)It should not be too hard but, as you pointed out, there is one limitation : the first column should not be hidden (unless the way you store hierarchy allows it...). If you still have problems you should send some code...
Implementing this as a part of model will lose all the flexibility mode/view framework provides. This model needs to connect to two views.

Which code do you want? For model class data is basically represented like in qt's example of simpletreemodel. It is further worked on to extend the functionality of sorting, filtering, and drag&drop moving. All this means relevant code is of about 1000 lines.

For how columns are shown/hidden/managed is like this:


void GMediaBrowser::updateViewColumnsSetup(Gravity::Pla ylistViewType view_type){
if(view_type != mViewType)
return;
QHeaderView *header = m_pModelView->header();
QList<GPlaylistViewColumns::Arrangement> arrangement = Gravity::self()->playlistViewColumns()->arrangement(mViewType);
for(int i = 0; i < arrangement.size(); ++i){
const GPlaylistViewColumns::Arrangement arr = arrangement.at(i);
header->setResizeMode(arr.colId - 1, arr.resizeMode);
header->moveSection(header->visualIndex(arr.colId - 1), i);
header->setSectionHidden(arr.colId - 1, !arr.isVisible);
}
}