Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 7

Qt-interest Archive, May 2007
QStandardItemModel, QTableView: sorting a double value


Message 1 in thread

Hello !

Is there a simple solution, how I can sort a QTableView as double ?

I use the QStandardItemModel with QStandardItems, that get sorted by 
QTableView as QString,
I want to sort one column as double.

Is there a simple way ?

As QString, the sorting looks so:
1, 100, 2, 3, 30, 4, and so on

The Qt version is 4.3.0

Thanks a lot !

Best Regards

Heiko Steindl


--
 [ signature omitted ] 

Message 2 in thread

I suggest looking at using your own model, or deriving from 
QStandardItemModel and implement the sort behavior you want.  Guess 
that's not so simple, but would work.

HTH,
Susan

Heiko Steindl wrote:
> Hello !
>
> Is there a simple solution, how I can sort a QTableView as double ?
>
> I use the QStandardItemModel with QStandardItems, that get sorted by 
> QTableView as QString,
> I want to sort one column as double.
>
> Is there a simple way ?
>
> As QString, the sorting looks so:
> 1, 100, 2, 3, 30, 4, and so on
>
> The Qt version is 4.3.0
>



---

This communication contains confidential information. If you are not the intended recipient please return this email to the sender and delete it from your records.

Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den Absender zurück und löschen Sie die E-mail aus Ihrem System.

--
 [ signature omitted ] 

Message 3 in thread

I'll try it, thanks a lot for your help !


Heiko


Susan Macchia schrieb:
> I suggest looking at using your own model, or deriving from 
> QStandardItemModel and implement the sort behavior you want.  Guess 
> that's not so simple, but would work.
>
> HTH,
> Susan
>
> Heiko Steindl wrote:
>> Hello !
>>
>> Is there a simple solution, how I can sort a QTableView as double ?
>>
>> I use the QStandardItemModel with QStandardItems, that get sorted by 
>> QTableView as QString,
>> I want to sort one column as double.
>>
>> Is there a simple way ?
>>
>> As QString, the sorting looks so:
>> 1, 100, 2, 3, 30, 4, and so on
>>
>> The Qt version is 4.3.0
>>
>
>
>
> ---
>
> This communication contains confidential information. If you are not 
> the intended recipient please return this email to the sender and 
> delete it from your records.
>
> Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht 
> der beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese 
> an den Absender zurück und löschen Sie die E-mail aus Ihrem System.
>
> -- 
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>

--
 [ signature omitted ] 

Message 4 in thread

Little help on how :)

First, derive from the model, and create a custom role, that returns in the qvariant the double value.

Then create a custom sort proxy model (derive from QSortFilterProxyModel) and override the lessThan method.

For the 2 QMI's sent in to the lessThan method, get the value of the custom role you created (.data( CUSTOM_ROLE ))

Set the standard model as the soruce for the proxy model.

Set the proxy as the model for the view...

Done.

Scott


> -----Original Message-----
> From: Susan Macchia [mailto:qt-list@xxxxxxxxxxxxx]
> Sent: Thursday, May 31, 2007 5:38 AM
> To: qt-interest@xxxxxxxxxxxxx
> Cc: qt-interest@xxxxxxxxxxxxx
> Subject: Re: QStandardItemModel, QTableView: sorting a double value
> 
> I suggest looking at using your own model, or deriving from
> QStandardItemModel and implement the sort behavior you want.  Guess
> that's not so simple, but would work.
> 
> HTH,
> Susan
> 
> Heiko Steindl wrote:
> > Hello !
> >
> > Is there a simple solution, how I can sort a QTableView as double ?
> >
> > I use the QStandardItemModel with QStandardItems, that get sorted by
> > QTableView as QString,
> > I want to sort one column as double.
> >
> > Is there a simple way ?
> >
> > As QString, the sorting looks so:
> > 1, 100, 2, 3, 30, 4, and so on
> >
> > The Qt version is 4.3.0
> >
> 
> 
> 
> ---
> 
> This communication contains confidential information. If you are not the
> intended recipient please return this email to the sender and delete it
> from your records.
> 
> Diese Nachricht enthält vertrauliche Informationen. Sollten Sie nicht der
> beabsichtigte Empfänger dieser E-mail sein, senden Sie bitte diese an den
> Absender zurück und löschen Sie die E-mail aus Ihrem System.
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 5 in thread

Scott Aron Bloom wrote:
> Little help on how :)
>
> First, derive from the model, and create a custom role, that returns in the qvariant the double value.
>
> Then create a custom sort proxy model (derive from QSortFilterProxyModel) and override the lessThan method.
>
> For the 2 QMI's sent in to the lessThan method, get the value of the custom role you created (.data( CUSTOM_ROLE ))
>
> Set the standard model as the soruce for the proxy model.
>
> Set the proxy as the model for the view...
>
> Done.
>
>   

You can also use QSortFilterProxy's setSortRole() property as long as 
the variant type is something the standard lessThan() supports. There are:
    QVariant::Int
    QVariant::UInt
    QVariant::LongLong
    QVariant::ULongLong
    QVariant::Double
    QVariant::Char
    QVariant::Date
    QVariant::Time
    QVariant::DateTime
    QVariant::String

Good Luck,
--Justin

begin:vcard
begin:vcard
fn:Justin Noel
n:Noel;Justin
org:ICS;Engineering
adr:;;54B Middlesex Trpk;Bedford;MA;01730;USA
email;internet:justin@xxxxxxx
title:Sr. Consulting Engineer / Certified Qt Instructor
tel;work:(617) 621-0060
url:http://www.ics.com
version:2.1
end:vcard


Message 6 in thread

> -----Original Message-----
> From: Justin Noel [mailto:justin@xxxxxxx]
> Sent: Thursday, May 31, 2007 8:47 AM
> To: QtList
> Subject: Re: QStandardItemModel, QTableView: sorting a double value
> 
> Scott Aron Bloom wrote:
> > Little help on how :)
> >
> > First, derive from the model, and create a custom role, that returns
in
> the qvariant the double value.
> >
> > Then create a custom sort proxy model (derive from
> QSortFilterProxyModel) and override the lessThan method.
> >
> > For the 2 QMI's sent in to the lessThan method, get the value of the
> custom role you created (.data( CUSTOM_ROLE ))
> >
> > Set the standard model as the soruce for the proxy model.
> >
> > Set the proxy as the model for the view...
> >
> > Done.
> >
> >
> 
> You can also use QSortFilterProxy's setSortRole() property as long as
> the variant type is something the standard lessThan() supports. There
are:
>     QVariant::Int
>     QVariant::UInt
>     QVariant::LongLong
>     QVariant::ULongLong
>     QVariant::Double
>     QVariant::Char
>     QVariant::Date
>     QVariant::Time
>     QVariant::DateTime
>     QVariant::String
> 
> Good Luck,
> --Justin
I really need to go update some of my code :)

I always forget they made the sort/filter proxy a ton easier to use in
4.2 :)

Scott

--
 [ signature omitted ]