十进制QTableView委托后的数字 [英] Digits after the decimal QTableView delegate

查看:56
本文介绍了十进制QTableView委托后的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于QTableView的项目,我需要在小数点后指定数字位数,因此我编写了一个简单的委托.

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;
   }
};

但是它不起作用,构造函数被调用,但displayText()函数却不起作用.

But it doesn`t work, constructor called, but not the displayText() function.

TableItemDelegate *decDelegate = new TableItemDelegate(tableView);
tableView->setItemDelegate(decDelegate);

我做错了什么?

推荐答案

您的方法未调用是因为您忘记了函数签名末尾的 const 说明符:

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

这篇关于十进制QTableView委托后的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆