On Friday 25 July 2008, Paul Miller wrote:
> I note in QStyledItemDelegate there is a displayText() method, which
> would have been perfect, but there is no QModelIndex passed in so I can
> determine what kind of item it is.
The QModelIndex is passed in via the paint() method, which is const. The Item
Delegates are pretty much flyweights with the data being extrinsic. Thus,
once it actually comes time to paint the data, you'll have sufficient
> You mentioned using a custom role - I've never done this. Would I have
> my delegate query my UserCurrencyRole from the model, and it if it gets
> back a non-null value, assume I can treat the data as currency?
You can use a custom role or a normal role as long as you have sufficient
information available for the delegate to be able to determine how it should
be presented and handled. When you set the data, rather than setting the
data with DisplayRole or EditRole, you'll just set it with Qt::UserRole + N
for some value of N. The custom role is particularly useful if you are
storing the data as a builtin type such as QString, int or double.
Another possibility, if you have a custom datatype for representing currency,
is to base the delegate off of that type and register a custom factory so
that an appropriate editor is created. See:
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/