Reimplement bool operator< ( const QTreeWidgetItem & other ) const for your tree items and use the created subclass instead of QTreeWidgetItem.
Reimplement bool operator< ( const QTreeWidgetItem & other ) const for your tree items and use the created subclass instead of QTreeWidgetItem.
Ok I reimplemented that in this way. However, will this sort "names" as well in alphabetical even if I override the original < operator? Or should I code that in too?
Qt Code:
#include "XTreeItem.h" int iScore, iMyScore; iScore = 0; iMyScore = 0; if(other.flags() == 0){ } if(flags() == 0){ } if(iMyScore < iScore){ return true; } else { return false; } } #include "XTreeItem.moc"To copy to clipboard, switch view to plain text mode
I know I shoulda used switches and/or functions better (more OO) but still is this basically what I should do to add weights?
What original operator? You have to subclass and reimplement the method in the subclass.
That's what I did, is the code correct?
This doesn't look like a subclass.Qt Code:
To copy to clipboard, switch view to plain text mode
Because I forgot to change the name of the class, but yes, assume it is a subclass. You still have not commented on the actual code?
It's hard to understand it... Besides, it doesn't do much sorting... For instance it doesn't seem to compare values of items at all... Only their "flags". Is "flags" the only property of your items?
Well my toplevel nodes have 0 flags, so its only way to detect them, the rest have flags. And I'm assuming Qt will sort the rest by default (in other words my function and original function working together)
No. Top level nodes don't have parents. That's a way to detect them.
But you never call the base class implementation so only your method gets called. That's how virtual methods work.And I'm assuming Qt will sort the rest by default (in other words my function and original function working together)
So how do I call it...?
Do I call it like this:
bool XTreeItem:perator< ( const QTreeWidgetItem & other ) const : QTreeWidgetItem:
perator< (other) {
Last edited by VireX; 21st May 2007 at 21:03.
Callin appropriate place of your reimplementation.Qt Code:
To copy to clipboard, switch view to plain text mode
Thought so, thank you, lemme try this stuff.
Bookmarks