Digits after the decimal QTableView delegate

2019-07-19 06:59发布

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?

1条回答
祖国的老花朵
2楼-- · 2019-07-19 07:29

Your method isn't called because you forgot the const specifier at the end of the function signature:

QString displayText(const QVariant & value, const QLocale & locale ) const
查看更多
登录 后发表回答