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 :
Code:
void Export_XLS ()
{
<stuff>
for ( int iRow = 0; iRow < m_GridModel->rowCount (); iRow++ )
ExportRow ( m_GridModel->index ( iRow, 0 ) );
<more stuff>
}
{
<...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 ?
Re: QTreView::isExpanded ( index ) allways false ?
just to make sure: do you perhaps use a proxy model between the QTreeView and your "grid model"?
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 :
Code:
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
Re: QTreView::isExpanded ( index ) allways false ?
Quote:
Originally Posted by
caduel
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?