QTableWidget,只允许输入数字

发布于 2024-08-10 08:59:00 字数 158 浏览 5 评论 0 原文

我有一个带有四列的QTableWidget。我希望用户能够在前三个中仅插入整数,在第四个中插入双精度数。

我相信这可以通过委托来完成,但我还没有找到相关的示例(只有一些带有QDateTimeEdit)。

我应该怎么办?

I have a QTableWidget with four columns. I want the user to be able to insert only integers in the first three and a double in the fourth.

I believe that this can be done with delegate, but I have not found relevant examples (only some with QDateTimeEdit).

What should I do?

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

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

发布评论

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

评论(1

烟燃烟灭 2024-08-17 08:59:00

查看 QItemDelegate 的文档;它提供了关于如何使用它的很好的描述。

由于使用委托,您将能够提供自己的自定义编辑器,因此我建议您使用 QLineEdit 以及使用 setValidator()。我相信类 QIntValidatorQDoubleValidator 在这种情况下将是完美的。

Look at the documentation for QItemDelegate; it provides a pretty good description on how it can be used.

Since with a delegate, you'll be able to provide your own custom editor, I would suggest that you use a QLineEdit with a validator set using setValidator(). I believe the classes QIntValidator and QDoubleValidator will be perfect in this situation.

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