QSpinBox 千位分隔符

发布于 2025-01-04 23:09:44 字数 56 浏览 1 评论 0原文

使用 QSpinBox 可以在用户输入数字时显示数字的千位分隔符 大约10,000 哪种方法最好?

With a QSpinBox is it possible to display the thousand separator of a number while user enter it
like 10,000
Which is the best way to do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝戈者 2025-01-11 23:09:44

我知道这已经晚了,但这可能对其他人有帮助。我用它来更新千位分隔符

ui->doubleSpinBox->setGroupSeparatorShown(true);

以 ui

在我的 QDialog 表单中我使用了这个要使用千位分隔符更新金额,

void DialogCashPayment::on_doubleSpinBox_valueChanged(double arg1){
     ui->doubleSpinBox->setValue(arg1);
}

编辑:

发现一个bug,当金额为10k以上时,光标位置发生变化。我还不知道如何解决这个问题。也许有人可以解决这个问题。

i know this is late but this may help other people. i used this to update the thousand separator

ui->doubleSpinBox->setGroupSeparatorShown(true);

or

set the property it in the form ui

In my QDialog Form i used this to update the amount with thousand separator,

void DialogCashPayment::on_doubleSpinBox_valueChanged(double arg1){
     ui->doubleSpinBox->setValue(arg1);
}

EDIT:

Found a bug when amount is 10k above, the cursor position is changed. i don't know how to fix this yet. Maybe someone could fix this.

帅气称霸 2025-01-11 23:09:44

您可以继承 QSpinBox 并重新实现 textFromValue 负责将值显示到旋转框小部件。可能的实现如下:

QString MySpinBox::textFromValue(int value)
{
   return this->locale()->toString(value);
}

使用 locale 是最好的方法,因为它将根据用户的设置显示分隔符。

You could subclass QSpinBox and reimplement the textFromValue which is responsible for the display of the value to the spinbox widget. A possible implementation could be the following:

QString MySpinBox::textFromValue(int value)
{
   return this->locale()->toString(value);
}

Using locale is the best way since it will display the separator based on the user's settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文