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

Qt-interest Archive, June 2007
QtreeWidget sorting : case sensitivity


Message 1 in thread

I want to sort my QTreeWidget (used as a non expandable items list) by a
column containing text.

It happens that it's sorted case sensitive, and I'd like to change that.

I must have missed something, but I did not find out where to do this.

Thanks in advance.

--
 [ signature omitted ] 

Message 2 in thread

"eb" <eb5@xxxxxxxxxx> wrote in message 
news:f3prfo$43$1@xxxxxxxxxxxxxxxxxxxxx
>I want to sort my QTreeWidget (used as a non expandable items list) by a
> column containing text.
>
> It happens that it's sorted case sensitive, and I'd like to change that.
>
> I must have missed something, but I did not find out where to do this.

Derive your own TreeWidgetItem from QTreeWidgetItem and override the < 
operator. 


--
 [ signature omitted ] 

Message 3 in thread

Duane Hebert wrote:

> 
> "eb" <eb5@xxxxxxxxxx> wrote in message
> news:f3prfo$43$1@xxxxxxxxxxxxxxxxxxxxx
>>I want to sort my QTreeWidget (used as a non expandable items list) by a
>> column containing text.
>>
>> It happens that it's sorted case sensitive, and I'd like to change that.
>>
>> I must have missed something, but I did not find out where to do this.
> 
> Derive your own TreeWidgetItem from QTreeWidgetItem and override the <
> operator.
 
eh ???
Thanks for the tip, but this seems to me a real overkill !!
I'm not wanting to create a subclass just for reimplementing an operator ...

Anything more straightforward for beginners ?

--
 [ signature omitted ] 

Message 4 in thread

"eb" <eb5@xxxxxxxxxx> wrote in message 
news:f3ptc3$bkk$1@xxxxxxxxxxxxxxxxxxxxx
> eh ???
> Thanks for the tip, but this seems to me a real overkill !!
> I'm not wanting to create a subclass just for reimplementing an operator 
> ...
>
> Anything more straightforward for beginners ?

?? How else would you reimplement an operator?

At any rate, I don't think there's a simpler method.  QTreeWidget uses
the QTreeWidgetItem < operator for sorting.

Assuming that case makes sense, something like:

class TreeWidgetItem : public QTreeWidgetItem {
public:
   TreeWidgetItem(QTreeWidget* parent):QTreeWidgetItem(parent){}
private:
   bool operator<(const QTreeWidgetItem &other)const {
       int column = treeWidget()->sortColumn();
       return text(column).toLower() < other.text(column).toLower();
    }
};



--
 [ signature omitted ] 

Message 5 in thread

Your probably only talking 20-30 lines of code.....

class CMySorterItem : public QTreeWidgetItem
{
public:
	CMySorterItem() : QTreeWidgetItem()
	{
	}

	bool operator<( const QTreeWidgetItem * rhs ) 
	{
		return text( 0 ).toLower() < rhs->text( 0 ).toLower();
	}
};

Don't get much easier then that
	


> -----Original Message-----
> From: eb [mailto:eb5@xxxxxxxxxx]
> Sent: Friday, June 01, 2007 12:52 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: QtreeWidget sorting : case sensitivity
> 
> Duane Hebert wrote:
> 
> >
> > "eb" <eb5@xxxxxxxxxx> wrote in message
> > news:f3prfo$43$1@xxxxxxxxxxxxxxxxxxxxx
> >>I want to sort my QTreeWidget (used as a non expandable items list)
by a
> >> column containing text.
> >>
> >> It happens that it's sorted case sensitive, and I'd like to change
> that.
> >>
> >> I must have missed something, but I did not find out where to do
this.
> >
> > Derive your own TreeWidgetItem from QTreeWidgetItem and override the
<
> > operator.
> 
> eh ???
> Thanks for the tip, but this seems to me a real overkill !!
> I'm not wanting to create a subclass just for reimplementing an
operator
> ...
> 
> Anything more straightforward for beginners ?
> 
> --
> 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 6 in thread

>class CMySorterItem : public QTreeWidgetItem
>{
>public:
>CMySorterItem() : QTreeWidgetItem()
>{
>}

>bool operator<( const QTreeWidgetItem * rhs )
>{
>return text( 0 ).toLower() < rhs->text( 0 ).toLower();
>}
>};
>
>Don't get much easier then that

Another line of code and you can have it use the
selected sort column <g>



> -----Original Message-----
> From: eb [mailto:eb5@xxxxxxxxxx]
> Sent: Friday, June 01, 2007 12:52 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Re: QtreeWidget sorting : case sensitivity
>
> Duane Hebert wrote:
>
> >
> > "eb" <eb5@xxxxxxxxxx> wrote in message
> > news:f3prfo$43$1@xxxxxxxxxxxxxxxxxxxxx
> >>I want to sort my QTreeWidget (used as a non expandable items list)
by a
> >> column containing text.
> >>
> >> It happens that it's sorted case sensitive, and I'd like to change
> that.
> >>
> >> I must have missed something, but I did not find out where to do
this.
> >
> > Derive your own TreeWidgetItem from QTreeWidgetItem and override the
<
> > operator.
>
> eh ???
> Thanks for the tip, but this seems to me a real overkill !!
> I'm not wanting to create a subclass just for reimplementing an
operator
> ...
>
> Anything more straightforward for beginners ?
>
> --
> 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 7 in thread

Hi,

> eh ???
> Thanks for the tip, but this seems to me a real overkill !!
> I'm not wanting to create a subclass just for reimplementing an operator ...
> 
> Anything more straightforward for beginners ?

Very often beginners complain that they don't want to derive a class. However 
that's not a long or difficult process. It is commonly used in object-oriented 
programming.

Now it's true that in C++ one has to redefine the constructors in addition to 
the function that must be overridden, but that's just a few lines of code. 
That could even be automated in the editor.

--
 [ signature omitted ] 

Message 8 in thread

> Hi,
> 
> > eh ???
> > Thanks for the tip, but this seems to me a real overkill !!
> > I'm not wanting to create a subclass just for reimplementing an
operator
> ...
> >
> > Anything more straightforward for beginners ?
> 
> Very often beginners complain that they don't want to derive a class.
> However
> that's not a long or difficult process. It is commonly used in object-
> oriented
> programming.
> 
> Now it's true that in C++ one has to redefine the constructors in
addition
> to
> the function that must be overridden, but that's just a few lines of
code.
> That could even be automated in the editor.
> 
> --
> Dimitri
> 
And in the next version of C++ (in 2009) the constructor requirement
(and other overloaded issues) will be removed

Scott

--
 [ signature omitted ]