Hi All,
I try to do something similar, but I have some issues when trying to overload the operator<
The problem is that I can't recover my original item from the list, I think that I'm wrong in the way I'm extracting it frm the list because I have to use a lots of const_cast, and is suspicious.
Here is the overload code for the operator
struct CustomListWidgetItem : QListWidgetItem
{
CustomListWidgetItem(QListWidget *view =0,int type = Type) : QListWidgetItem(view,type){}
bool operator< ( const QListWidgetItem & other ) const
{
QListWidget * list1 = this->listWidget();
QListWidget * list2 = other.listWidget();
QWidget * w1 = list1->itemWidget(const_cast<CustomListWidgetItem *>(this));
QWidget * w2 = list2->itemWidget(const_cast<QListWidgetItem *>(&other));
Item item1 = (reinterpret_cast<InCallItem*>(w1))->getItem();
Item item2 = (reinterpret_cast<InCallItem*>(w2))->getItem();
return item1 < item2;
}
};
Note:
- list1 == list2 (both items are in the same list)
- w2 == NULL (Why? is correct the way I'm getting w2? should it be of the custom type? perhaps a dynamic_cast?)
- Is there any problem if two items are equivalent? Item1 == Item2 ?
thanks in advence
Bookmarks