PDA

View Full Version : QTreView::isExpanded ( index ) allways false ?



jpujolf
20th February 2009, 12:55
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 :



void Export_XLS ()
{
<stuff>
for ( int iRow = 0; iRow < m_GridModel->rowCount (); iRow++ )
ExportRow ( m_GridModel->index ( iRow, 0 ) );
<more stuff>
}

void ExportRow ( const QModelIndex & index )
{
<...export data for this row...>
if ( !m_Tree->isExpanded ( index ) ||
!m_GridModel->hasChildren ( index ) ) return;

// Recursive call
for ( int iChild = 0; iChild < m_GridModel->rowCount ( index ); iChild++ )
ExportRow ( index.child ( iChild, 0 ) );
}


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 ?

caduel
20th February 2009, 16:22
just to make sure: do you perhaps use a proxy model between the QTreeView and your "grid model"?

jpujolf
23rd February 2009, 07:41
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 :



connect ( m_GridWidgetLock, SIGNAL ( expanded ( const QModelIndex & ) ), m_GridWidget, SLOT( expand ( const QModelIndex & ) ) );
connect ( m_GridWidgetLock, SIGNAL ( collapsed ( const QModelIndex & ) ), m_GridWidget, SLOT ( collapse ( const QModelIndex & ) ) );
connect ( m_GridWidget, SIGNAL ( expanded ( const QModelIndex & ) ), m_GridWidgetLock, SLOT ( expand ( const QModelIndex & ) ) );
connect ( m_GridWidget, SIGNAL ( collapsed ( const QModelIndex & ) ), m_GridWidgetLock, SLOT ( collapse ( const QModelIndex & ) ) );


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 :D

snooker
24th September 2010, 10:23
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?