我在pyqt5程序中使用了QDoubleValidator,但它似乎不起作用

时间:2019-02-18 05:51:59

标签: python python-3.x pyqt pyqt5 qlineedit

我制作了一个包含一些lineEdits的QWidget对象,并且打算向它们添加一些约束,因此我实现了QDoubleValidator对象。 以下是我代码中的相关部分。

self.lineEdit_taxRate= QLineEdit()
self.lineEdit_taxRate.setValidator(QDoubleValidator(0.0, 100.0, 6))

但是,当我运行程序时,发现仍然可以输入数字123165.15641。看来验证者没有任何作用。

我想知道我错过了哪一步,否则验证器会触发一些信号。

lineEdit

1 个答案:

答案 0 :(得分:1)

默认情况下,QDoubleValidator使用ScientificNotation notation,并且该符号123165.15641是可能的有效值,因为它可以转换为123165.15641E-100,并且该数字介于0和100之间。在这种情况下解决方案是建立使用标准符号的方法:

#Ecto.Changeset<
  action: :insert,
  changes: %{
    email: "test@test.com",
    organization: #Ecto.Changeset<action: :update, changes: %{}, errors: [],
     data: #MyApp.Organizations.Organization<>, valid?: true>,
    password: "test",
    password_confirmation: "test",
    password_hash: "bla"
  },
  errors: [
    email: {"has already been taken",
     [constraint: :unique, constraint_name: "accounts_users_email_index"]}
  ],
  data: #MyApp.Accounts.User<>,
  valid?: false
>