[Qt-interest] Delegate for QPixMap and Background Color
peter
qt at bienert-rh.de
Thu Apr 22 08:27:38 CEST 2010
Hi,
I have some problems dealing with a delegate for QTableView, that
handles Qt::DecorationRole or Qt::TextColorRole,
I wrote some working delegates for converting some sql table stuff into
international Date, Time output and so on, but I cannot get the above
things to work...
Could anyone help here ?
Here is one of my classes:
Declaration:
class PB_DLLEXPORT PBTextTranslateDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
PBTextTranslateDelegate(QObject *parent, QStringList texte, QString
Fehler = Texte.Datenfehler);
~PBTextTranslateDelegate();
QString displayText ( const QVariant & value, const QLocale &
locale ) const;
private:
QStringList Text;
QString Fehler;
};
Implementation:
PBTextTranslateDelegate::PBTextTranslateDelegate(QObject *parent,
QStringList liste, QString _Fehler)
:QStyledItemDelegate(parent)
{
Text = liste;
Fehler = _Fehler;
}
PBTextTranslateDelegate::~PBTextTranslateDelegate()
{
}
QString PBTextTranslateDelegate::displayText(const QVariant &value,
const QLocale &locale) const
{
int offset = value.toInt();
if ((offset >= 0) && (offset < Text.count()))
return Text.at(offset);
return Fehler;
}
Actually I solve this with a overwritten model class from i.e.
QSqlQueryModel or a self written Models for some data structures, but
for the standard case, it is better to use a delegate for a column...
Regards,
Peter
More information about the Qt-interest-old
mailing list