[Interest] QTreeView and dynamic sorting
Igor Mironchik
igor.mironchik at gmail.com
Wed Oct 16 15:04:28 CEST 2013
Forgot to say that I use
d->m_sortModel->setDynamicSortFilter(false);
because of dynamic sorting moves the rows with the same value in a
sorted column in its sole discretion from time to time.
> Hi.
>
> I use QTreeView to display dynamic data. I.e. rows can be inserted
> during program execution dynamically and values in some column can be
> changed dynamically too. But I need QTreeView to be sorted by the
> given by user column when new rows added.
>
> I've connected to the rowsInserted signal:
>
> connect(d->m_model,
> SIGNAL( rowsInserted( const QModelIndex &, int, int ) ),
> this, SLOT( rowsAdded( QModelIndex, int, int ) ) );
>
> And in the slot I do the next:
>
> void
> ChannelView::rowsAdded( const QModelIndex & parent, int start, int end )
> {
> Q_UNUSED( parent )
> Q_UNUSED( start )
> Q_UNUSED( end )
>
>
> qDebug() << "SORT" << parent << start << end;
>
> d->m_sortModel->sort( d->m_sortModel->sortColumn(),
> d->m_sortModel->sortOrder() );
> }
>
> But I see that QTreeView doesn't sorted by the given column when the data in that column is static.
>
> In the debug print I see the next:
>
> SORT QModelIndex(-1,-1,0x0,QObject(0x0)) 0 -1
> SORT QModelIndex(-1,-1,0x0,QObject(0x0)) 0 0
> SORT QModelIndex(-1,-1,0x0,QObject(0x0)) 1 1
> SORT QModelIndex(-1,-1,0x0,QObject(0x0)) 2 2
>
> I've inserted three rows only but rowsInserted emitted four times. Why?
>
> What am I doing wrong?
>
> Thanks.
>
> --
> Best Regards,
> Igor Mironchik.
--
Best Regards,
Igor Mironchik.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131016/d044bf96/attachment.html>
More information about the Interest
mailing list