QDoubleSpinBox 有问题。“退格”键的编辑行为在某种程度上取决于后缀的大小。如果我将“m”设置为后缀,然后将光标设置在旋转框的末尾并按“退格”,光标会跳过“m”后缀的值,然后可以使用进一步的“退格”进行编辑。如果我将后缀设置为“mm”或任何双字母单词,则无论我按多少个“退格键”,光标都会停留在旋转框的末尾。
我尝试调试“validate”方法中的内容,得到了一个奇怪的结果:当光标在“0,00m”末尾时按下“退格”,验证收到“0,00m”。当光标在“0,00_m”末尾时按下“退格”时,验证接收“0,00__m” 当光标在“0,00_mm”末尾时按下“退格”时,验证接收“0, 00_m_mm"
这种行为的原因是什么,我该如何克服?
# coding=utf-8
from PyQt5 import QtWidgets
class SpinBox(QtWidgets.QDoubleSpinBox):
def __init__(self):
super().__init__()
def validate(self, text, index):
res = super().validate(text, index)
print(text, res, self.text())
return res
if __name__ == "__main__":
q_app = QtWidgets.QApplication([])
sb = SpinBox()
sb.setSuffix(" m")
sb.show()
q_app.exec_()