[Qt-interest] QTableView and delegate
Jason Wood
jason at comp.leeds.ac.uk
Fri Nov 6 15:00:05 CET 2009
Hi Wolfgan,
I think you can use a QAbstractItemDelegate and subclass it and
make it the delegate for a column. You then have access to its paint
method where you can do your translation from model data to view
and if you simply return NULL from the createEditor method the
items are non-editable.
--
jason
subclass it
> Hello Sean,
>
>> > if I have a read-only QTableView with a model containing integers in some
>> > column, and want to translate them into human-readable strings before
>> > displaying them in the table, what is the best design?
>> >
>> > I first thought about using a column delegate, however I noticed that it is only
>> > called if flags() returns Qt::ItemIsEditable, which is not what I want in a
>> > read only table... And even if flags() returns Qt::ItemIsEditable, the
>> > delegate seems to become active only if I click on the cell.
>> >
>> > I think I might get what I want by using QAbstractItemView::setIndexWidget for
>> > each cell where I want to translate ints to strings. But this would mean that
>> > I (a) would need custom widget classes, (b) would have several extra widgets
>> > per row and (c) would have to set them manually e.g. when adding/removing rows.
>> >
>> > What do you think, is the latter really the right design, or is there some
>> > simpler solution I missed so far?
>> >
>> You could use a proxy model to do the translation and set that on the
>> views where you wish to see human readable data. Or if this would be for
>> every view, just do the translation in your model class. If you later
>> decide to make it read/write you would have to do the reverse
>> translation in your model's setData() function.
>
> Yes this helps. (although I was aware of this possibility, I just hoped for one where I can avoid adding a proxy model).
>
> By the way, what´s the reason why delegates only work when editing data? I mean, passing the data through a delegate, calling it´s setEditorData method would be so easy and straightforward - at least for me as a user of the library...
>
> Thanks,
>
> Wolfgang
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list