[Qt-jambi-interest] QItemDelegate for *non-primitives* usingQComboBox
Curt Nowak
cnowak at bwl.uni-hildesheim.de
Tue Jul 1 16:58:21 CEST 2008
Hi all,
fyi, I tried my luck with a QStandardItemModel using QStandardItem#setData(Object o, int role) with role Qt.ItemDataRole.UserRole but that doesn't work either.
I'm guessing someone at Trolltech put a "QObject" at some place where a simple "Object" would have sufficed ;-)
My IntegerID-to-Object work-around works though. And if you use both QStandardItemModel#setData(int row, int col, Object o, Qt.ItemDataRole.UserRole ) as well as QStandardItemModel#setData(int row, int col, Object o, Qt.ItemDataRole.DisplayRole) in your MyItemDelegate#setModelData(QWidget editor, QAbstractItemModel model, QModelIndex index) than you won't even have to bother overwriting QItemDelegate#paint(QPainter, QStyleOptionViewItem, QModelIndex).
Cheers, Curt
________________________________
Von: qt-jambi-interest-bounces at trolltech.com im Auftrag von Curt Nowak
Gesendet: Mo 30.06.2008 13:37
An: Eskil Abrahamsen Blomfeldt
Cc: qt-jambi-interest at trolltech.com
Betreff: Re: [Qt-jambi-interest] QItemDelegate for *non-primitives* usingQComboBox
Hi Eskil,
thanks for your help. At least it's good to hear that it wasn't my fault...
If anyone's interested: I have come up with another work-around.
Save a HashMap<Integer, MyClass> inside your surrounding widget (either your own QTableWidget or the parent of the QTableWidget you are using). Since the ComboBoxDelegator does work wirh java.lang.Integer you can use it to store IDs of your more complex Objects. (I used java.awt.Point only for demonstration purpose.) Now all you have to do is take the extra step of translating your IDs back into "non-Qt jambi"-MyClass objects.
Of course your ComboBoxDelegate will have to overwrite paint(QPainter , QStyleOptionViewItem , QModelIndex ) in order to display something different than integers.
Curt
________________________________
Von: Eskil Abrahamsen Blomfeldt [mailto:eblomfel at trolltech.com]
Gesendet: Mo 30.06.2008 12:58
An: Curt Nowak
Cc: qt-jambi-interest at trolltech.com
Betreff: Re: [Qt-jambi-interest] QItemDelegate for *non-primitives* using QComboBox
Curt Nowak wrote:
> I'm trying to set up a QItemDelegate that shows a QComboBox as its editor and manages non-primitives internally. I modified the StarDelegate example so that it uses QComboBoxes for editors and works with java.awt.Point as "complex" objects. Unfortunately the table data never changes. However, if I use primitives instead it works perfectly fine. I just don't get it.
>
Hi, Curt.
This is a bug in Qt Jambi causing the QTableWidget to be incompatible
with any type not known to Qt Jambi.
The bug will be fixed for the next patch release. Meanwhile, the only
suggestions I have is that you either
1. Use QTableView and your own item model, as I believe these should not
suffer from the bug.
2. Convert your AWT Point objects to QPoint for setting them as data in
the model. Since QPoint is a specially handled class, it will avoid the bug.
Thank you for the report.
-- Eskil
_______________________________________________
Qt-jambi-interest mailing list
Qt-jambi-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest
More information about the Qt-jambi-interest
mailing list