Qt:如何在设计器中设置QLineEdit的验证器? [英] Qt: How do I set a QLineEdit's validator in the designer?

查看:744
本文介绍了Qt:如何在设计器中设置QLineEdit的验证器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个UI,我有一个情况,我有一个QLineEdit,我只需要接受整数。

I'm designing a UI at the moment, and I have a situation where I have a QLineEdit which I need to only accept integers.

我知道如何设置验证器在代码中使用QIntValidator。但是我想在设计器中这样做。

I know how to set the validator to use QIntValidator in code. But I'd like to do this in the designer.

如何在使用设计器时设置QLineEdit的验证器?

How can I set the QLineEdit's validator when using the designer?

注意:我不想使用输入掩码。输入掩码和验证器函数不同。

Note: I don't want to use an input mask. An input mask and a validator function differently.

推荐答案

你是如何100%通过设计器,这是在设计器中设计的?

Are you asking how to do it 100% through designer, or for a widget that was designed in designer?

你将需要在代码级别做它,无论什么,没有办法直接在设计器 - 所有的功能都暴露给它。

You're going to need to do it at the code level no matter what, there is no way to do it directly in designer - not all functionality is exposed to it.

出于好奇,为什么不使用QSpinBox如果你得到一个整数?你可以使用一个QSpinBox并将buttonSymbols设置为NoButtons,甚至指定一个后缀&前缀的文本,如果你想要的。最终结果看起来和行为几乎完全像一个QLineEdit,但专门针对整数值。

Out of curiosity, why not use a QSpinBox if you're getting purely an integer? You could use a QSpinBox and set the buttonSymbols to NoButtons, and even specify a suffix & prefix of text if you want. The end result looks and acts almost exactly like a QLineEdit, however is geared specifically for integer values.

这篇关于Qt:如何在设计器中设置QLineEdit的验证器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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