Results 1 to 5 of 5

Thread: Moving columns/hiding columns in QTreeView

  1. #1
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Moving columns/hiding columns in QTreeView

    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

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Moving columns/hiding columns in QTreeView

    Quote Originally Posted by yogeshm02 View Post
    What should I do
    Well, you should start by being a little more precise... 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...
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Moving columns/hiding columns in QTreeView

    Quote Originally Posted by fullmetalcoder View Post
    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.

  4. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Moving columns/hiding columns in QTreeView

    Quote Originally Posted by yogeshm02 View Post
    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...
    Current Qt projects : QCodeEdit, RotiDeCode

  5. #5
    Join Date
    Jan 2006
    Location
    India
    Posts
    115
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Moving columns/hiding columns in QTreeView

    Quote Originally Posted by fullmetalcoder View Post
    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:
    Qt Code:
    1. void GMediaBrowser::updateViewColumnsSetup(Gravity::PlaylistViewType view_type){
    2. if(view_type != mViewType)
    3. return;
    4. QHeaderView *header = m_pModelView->header();
    5. QList<GPlaylistViewColumns::Arrangement> arrangement = Gravity::self()->playlistViewColumns()->arrangement(mViewType);
    6. for(int i = 0; i < arrangement.size(); ++i){
    7. const GPlaylistViewColumns::Arrangement arr = arrangement.at(i);
    8. header->setResizeMode(arr.colId - 1, arr.resizeMode);
    9. header->moveSection(header->visualIndex(arr.colId - 1), i);
    10. header->setSectionHidden(arr.colId - 1, !arr.isVisible);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Changing the order of columns in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2006, 00:00

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.