I need a specified number of digits after the decimal point for the items of QTableView, so I wrote a simple delegate.
class TableItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
TableItemDelegate(QObject *parent = 0) : QStyledItemDelegate(parent) {}
QString displayText(const QVariant & value, const QLocale & locale)
{
QString str = QString::number(value.toDouble(), 'f', 8);
return str;
}
};
But it doesn`t work, constructor called, but not the displayText() function.
TableItemDelegate *decDelegate = new TableItemDelegate(tableView);
tableView->setItemDelegate(decDelegate);
What I`m doing wrong?
Your method isn't called because you forgot the
const
specifier at the end of the function signature: