July 5, 2011

umen242 umen242
Lab Rat
198 posts

Can i define differnt sort role to each column ?

 

Hello
currently im using SortRule in my QStandardItemModel that is based on Qt::UserRole
but this definition is globally to all the treeview .
can i define different sort rule to each set of vertial cell’s ?
so for example if i have:

  1. m_model->setHeaderData(0, Qt::Horizontal, QObject::tr("Group"));
  2.  m_model->setHeaderData(2, Qt::Horizontal, QObject::tr("Id"));

the first Group cells will be sorted by Qt::UserRole and the second Id will be sorted by Qt::DisplayRole

4 replies

July 5, 2011

Andre Andre
Robot Herder
6422 posts

I think you’ ll need to subclass QSFPM and reimplement lessThan, after which you can compare on the role that you want for the indicated column.

July 6, 2011

umen242 umen242
Lab Rat
198 posts

wow where can i find example how to do that ?
found ..
http://www.java2s.com/Code/Cpp/Qt/SubclassQSortFilterProxyModel.htm [java2s.com]

July 6, 2011

dialingo dialingo
Lab Rat
151 posts

You can have custom sorting for each column though there is only one sort role for the treeview. You define the sort order by writing values into the custom field that determine the position when sorting. You can even use different types in different columns. Or you can use a specific custom type for every column. Just make sure your custom type is registered with QVariant and defines a comparison operator.

July 6, 2011

umen242 umen242
Lab Rat
198 posts

Thanks allot for answering

 
  ‹‹ Why QHostAddress().toIPv4Address() is different from inet_addr()?      [SOLVED] [Qt Plugin] A simple question on plugins ››

You must log in to post a reply. Not a member yet? Register here!