Digits after the decimal QTableView delegate

浪尽此生 提交于 2019-12-11 04:07:36

问题


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:


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


来源:https://stackoverflow.com/questions/10064149/digits-after-the-decimal-qtableview-delegate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!