<legend id='8x8fS'><style id='8x8fS'><dir id='8x8fS'><q id='8x8fS'></q></dir></style></legend>

<i id='8x8fS'><tr id='8x8fS'><dt id='8x8fS'><q id='8x8fS'><span id='8x8fS'><b id='8x8fS'><form id='8x8fS'><ins id='8x8fS'></ins><ul id='8x8fS'></ul><sub id='8x8fS'></sub></form><legend id='8x8fS'></legend><bdo id='8x8fS'><pre id='8x8fS'><center id='8x8fS'></center></pre></bdo></b><th id='8x8fS'></th></span></q></dt></tr></i><div id='8x8fS'><tfoot id='8x8fS'></tfoot><dl id='8x8fS'><fieldset id='8x8fS'></fieldset></dl></div>

    <tfoot id='8x8fS'></tfoot>
    • <bdo id='8x8fS'></bdo><ul id='8x8fS'></ul>

    <small id='8x8fS'></small><noframes id='8x8fS'>

      1. PyQt QLineEdit 与 QValidator

        时间:2023-08-04

        <small id='JESyg'></small><noframes id='JESyg'>

          <tbody id='JESyg'></tbody>
        <legend id='JESyg'><style id='JESyg'><dir id='JESyg'><q id='JESyg'></q></dir></style></legend>
        <tfoot id='JESyg'></tfoot>
          • <bdo id='JESyg'></bdo><ul id='JESyg'></ul>
            <i id='JESyg'><tr id='JESyg'><dt id='JESyg'><q id='JESyg'><span id='JESyg'><b id='JESyg'><form id='JESyg'><ins id='JESyg'></ins><ul id='JESyg'></ul><sub id='JESyg'></sub></form><legend id='JESyg'></legend><bdo id='JESyg'><pre id='JESyg'><center id='JESyg'></center></pre></bdo></b><th id='JESyg'></th></span></q></dt></tr></i><div id='JESyg'><tfoot id='JESyg'></tfoot><dl id='JESyg'><fieldset id='JESyg'></fieldset></dl></div>

                  本文介绍了PyQt QLineEdit 与 QValidator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我的项目中有一个 QLineEdit.我想在 lineEdit 上使用 QValidation.

                  I have a QLineEdit in my project. I want to use the QValidation on lineEdit.

                  #Create lineEdit
                  itemValue = QtWidgets.QLineEdit()
                  #Create валидатор
                  objValidator = QtGui.QDoubleValidator(self)
                  #setup range
                  objValidator.setRange(-10.0, 100.0, 5)
                  #lineEdit with validation
                  itemValue.setValidator(objValidator)
                  

                  但效果不好.我可以输入我想要的,除了符号.而且范围不起作用!我可以输入 100500 或 -100500,但我希望,该用户只能输入范围内的数字.

                  But it doesn't work well.I can type what i want, except symbols. And range doesn't work!I can type 100500 or -100500, but i want, that user can enter numbers only in range.

                  我应该如何使用范围?我需要帮助:)

                  How i should use range? I need help:)

                  谢谢你们的帮助,伙计们!

                  Thanks for your help, guys!

                  推荐答案

                  默认情况下,验证器不会阻止输入超出范围的值,如果输入的值也不会阻止用户离开行编辑是无效或中间.

                  By default, a validator will not prevent values outside the range from being entered, and it won't prevent the user leaving the line-edit if the entered value is Invalid or Intermediate.

                  但是,它确实让您有机会以编程方式拒绝输入,因为只要当前值不可接受,行编辑就不会发出它的 editingFinished 或 returnPressed 信号,及其 hasAcceptableInput 方法将返回 False.另外,如果你子类化验证器,你可以重新实现它的 fixup 方法来控制输入的值.

                  However, it does give you an opportunity to reject the input programmatically, because whenever the current value is unacceptable, the line-edit won't emit its editingFinished or returnPressed signals, and its hasAcceptableInput method will return False. In addition, if you subclass the validator, you can reimplement its fixup method to control the values that are entered.

                  然而,正如已经建议的那样,更好/更简单的解决方案是使用 QDoubleSpinBox,因为它会自动清理输入并提供更友好的用户界面.

                  However, as has been suggested already, a far better/simpler solution is to use a QDoubleSpinBox, since it cleans up the input automatically and provides a more user-friendly interface.

                  这篇关于PyQt QLineEdit 与 QValidator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 Python 将控制台输出定向到 pyqt5 plainTe 下一篇:如何使用 Pyqt5 QtMultimedia 播放声音?

                  相关文章

                  最新文章

                  1. <i id='uKqIm'><tr id='uKqIm'><dt id='uKqIm'><q id='uKqIm'><span id='uKqIm'><b id='uKqIm'><form id='uKqIm'><ins id='uKqIm'></ins><ul id='uKqIm'></ul><sub id='uKqIm'></sub></form><legend id='uKqIm'></legend><bdo id='uKqIm'><pre id='uKqIm'><center id='uKqIm'></center></pre></bdo></b><th id='uKqIm'></th></span></q></dt></tr></i><div id='uKqIm'><tfoot id='uKqIm'></tfoot><dl id='uKqIm'><fieldset id='uKqIm'></fieldset></dl></div>

                      <bdo id='uKqIm'></bdo><ul id='uKqIm'></ul>

                  2. <tfoot id='uKqIm'></tfoot>

                    <small id='uKqIm'></small><noframes id='uKqIm'>

                    1. <legend id='uKqIm'><style id='uKqIm'><dir id='uKqIm'><q id='uKqIm'></q></dir></style></legend>