
Originally Posted by
ChrisW67
This happens, presumably, because QVariant::isNull() calls QPoint::isNull() which returns true for QPoint(0,0).
That's probably the reason. A quick work around is:
#include <QtGui>
#include <QDebug>
class PointDelegate : public QStyledItemDelegate
{
public:
PointDelegate
(QObject *parent
= 0): QStyledItemDelegate
(parent
) {};
{
if (QVariant::Point == index.
data().
type()) return displayText
(index.
data,
QLocale::system());
else
return QStyledItemDelegate::paint(painter, option, index);
}
{
Q_UNUSED(locale);
qDebug() << "Delegate called with " << value;
return QString("{%1,%2}").
arg(value.
toPoint().
x()).
arg(value.
toPoint().
y());
}
};
#include <QtGui>
#include <QDebug>
class PointDelegate : public QStyledItemDelegate
{
public:
PointDelegate(QObject *parent = 0): QStyledItemDelegate(parent) {};
void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index )
{
if (QVariant::Point == index.data().type())
return displayText(index.data, QLocale::system());
else
return QStyledItemDelegate::paint(painter, option, index);
}
virtual QString displayText(const QVariant & value, const QLocale & locale ) const
{
Q_UNUSED(locale);
qDebug() << "Delegate called with " << value;
return QString("{%1,%2}").arg(value.toPoint().x()).arg(value.toPoint().y());
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks