Results 1 to 4 of 4

Thread: QTreView::isExpanded ( index ) allways false ?

  1. #1
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTreView::isExpanded ( index ) allways false ?

    Hi all,

    I'm confused. Something wrong in my code or a Qt bug ?

    I've a QTreeView, showing data as a grid with groups. I've implemented an "export to excel" method, that exports all model's data shown. First attempt worked. I can export all data, not AS shown. If a row is grouped, I export too its children.

    Now, Im testing if every node is expanded and I can export only expanded rows, as must be...

    Code is like this :

    Qt Code:
    1. void Export_XLS ()
    2. {
    3. <stuff>
    4. for ( int iRow = 0; iRow < m_GridModel->rowCount (); iRow++ )
    5. ExportRow ( m_GridModel->index ( iRow, 0 ) );
    6. <more stuff>
    7. }
    8.  
    9. void ExportRow ( const QModelIndex & index )
    10. {
    11. <...export data for this row...>
    12. if ( !m_Tree->isExpanded ( index ) ||
    13. !m_GridModel->hasChildren ( index ) ) return;
    14.  
    15. // Recursive call
    16. for ( int iChild = 0; iChild < m_GridModel->rowCount ( index ); iChild++ )
    17. ExportRow ( index.child ( iChild, 0 ) );
    18. }
    To copy to clipboard, switch view to plain text mode 

    But now I've seen that only first level of tree is exported, because isExpanded ALLWAYS return false, even if I user expands items on screen or expandall is called.

    Why ?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreView::isExpanded ( index ) allways false ?

    just to make sure: do you perhaps use a proxy model between the QTreeView and your "grid model"?

  3. The following user says thank you to caduel for this useful post:

    jpujolf (25th February 2009)

  4. #3
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreView::isExpanded ( index ) allways false ?

    No, I derived QAbstractItemModel directly.

    The only thing "strange" I'm doing is a trick somebody said me in this forum. I need to lock some columns and I've implemented a double QTreeView ( two QtreeView's, putted together side by side ), the left one with fixed size containing the locked columns and the right one containing scrollable data.

    Both trees share the same model. I've connected signals between grids like this to maintain them in sync :

    Qt Code:
    1. connect ( m_GridWidgetLock, SIGNAL ( expanded ( const QModelIndex & ) ), m_GridWidget, SLOT( expand ( const QModelIndex & ) ) );
    2. connect ( m_GridWidgetLock, SIGNAL ( collapsed ( const QModelIndex & ) ), m_GridWidget, SLOT ( collapse ( const QModelIndex & ) ) );
    3. connect ( m_GridWidget, SIGNAL ( expanded ( const QModelIndex & ) ), m_GridWidgetLock, SLOT ( expand ( const QModelIndex & ) ) );
    4. connect ( m_GridWidget, SIGNAL ( collapsed ( const QModelIndex & ) ), m_GridWidgetLock, SLOT ( collapse ( const QModelIndex & ) ) );
    To copy to clipboard, switch view to plain text mode 

    I've tested today a little bit and was my mistake. I was testing if m_GridWidget->isExpanded ( QModelIndex & index ) with column value = 0. Obviously, when I'm locking columns, I'm hiding the locked ones in right tree ( 0..L-1, where L is the number of locked columns )

    And I was testing column 0, on THAT tree at the right side. Grrrrr. Wednesday is not a good day for debugging .

    Thanks a lot Caduel, you pointed me in the right direction

  5. #4
    Join Date
    May 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreView::isExpanded ( index ) allways false ?

    Quote Originally Posted by caduel View Post
    just to make sure: do you perhaps use a proxy model between the QTreeView and your "grid model"?
    I have the same problem and I am using Proxy mode. Why isExpanded() function behavior is wrong in this case?

Similar Threads

  1. Problem with connect()
    By mrnor3 in forum Qt Programming
    Replies: 3
    Last Post: 23rd July 2008, 14:05
  2. Qtopia core 4.2.2 cross compile make error
    By smiyai18 in forum Installation and Deployment
    Replies: 2
    Last Post: 28th August 2007, 17:04

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.