[Qt-interest] QTableView and delegate
Sean Harmer
sean.harmer at maps-technology.com
Thu Nov 5 21:32:25 CET 2009
Hi,
Wolfgang Pausch wrote:
> Hello,
>
> 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.
Hope this helps,
Sean
More information about the Qt-interest-old
mailing list