Qt-interest Archive, May 2007
How to change the view ordering?
Message 1 in thread
Hi,
I want a listview to start with descending sorting. Is there a bug or why does
it not work to call proxy->sort()?
m_Model = new QStandardItemModel(this);
m_Proxy = new QSortFilterProxyModel(this);
m_Proxy->sort(0, Qt::DescendingOrder);
m_Proxy->setSourceModel(m_Model);
treeJrn->setModel(m_Proxy);
I called it before and after putting data into the view, no change.
Calling
treeJrn->sortByColumn(0, Qt::DescendingOrder);
has the same effect.
And calling
treeJrn->header()->setSortIndicator(0, Qt::AscendingOrder);
changes only the indicator of the header...
-----------------------------------
Forty-Three GmbH
Neugrabenweg 5-7
66123 Saarbrücken
Fon: +49 (0)681-95814-0
Fax: +49 (0)681-95814-14
HRB 13266 Amtsgericht Saarbrücken
Geschäftsführer: Dr. Christian Gill
--
[ signature omitted ]
Message 2 in thread
> m_Proxy->sort(0, Qt::DescendingOrder);
> m_Proxy->setSourceModel(m_Model);
Shouldn't you set the source model first and sort afterwards. The
proxy has nothing to sort...
--
[ signature omitted ]
Message 3 in thread
On Wednesday 23 May 2007 18:32:33 J-P Nurmi wrote:
> > m_Proxy->sort(0, Qt::DescendingOrder);
> > m_Proxy->setSourceModel(m_Model);
>
> Shouldn't you set the source model first and sort afterwards. The
> proxy has nothing to sort...
As I said: I tried it even before and after loading data into the view.
On the other hand: it should be ordered anyway, because the ordering mode is
set, which it's still active when I add data afterwards.
--
[ signature omitted ]
Message 4 in thread
> As I said: I tried it even before and after loading data into the view.
It doesn't matter whether a model is attached to a view, multiple
views or is not attached to a view at all, by the time it's being
sorted.
Calling
treeJrn->sortByColumn(0, Qt::DescendingOrder); // this is just a
convenience method
is exactly the same than doing:
treeJrn->header()->setSortIndicator(0, Qt::DescendingOrder);
treeJrn->model()->sort(0, Qt::DescendingOrder); // the actual sorting
is done in the model
What does matter is if the model has data to sort or not.
> On the other hand: it should be ordered anyway, because the ordering mode is
> set, which it's still active when I add data afterwards.
Actually this is only true for a dynamic QSortFilterProxyModel. See
http://doc.trolltech.com/4.2/qsortfilterproxymodel.html#dynamicSortFilter-prop
for more details.
--
[ signature omitted ]
Message 5 in thread
> treeJrn->sortByColumn(0, Qt::DescendingOrder); // this is just a
> Actually this is only true for a dynamic QSortFilterProxyModel. See
> http://doc.trolltech.com/4.2/qsortfilterproxymodel.html#dynamicSortFilter-p
>rop for more details.
Ok, thanx a lot. With setting the sorting proxy to dynamic and calling the
view's sorting function as you told, it works.
Now only the problem with setting the current/selected item is left, but one
after the other. Thank you!
--
[ signature omitted ]
Message 6 in thread
Hai,
I have a QListView "listView" with some data(QListViewItems). I want to copy
the same tree structure to another QListView tempListView.
How do I copy the structure? Can I use a listView = tempListView option. I
want a deep copy not a shallow copy.
Regards
DP
DISCLAIMER
âThe information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you"
--
[ signature omitted ]