gpt4 book ai didi

python - 未启用时将 QDoubleSpinBox 值设置为空字符串

转载 作者:行者123 更新时间:2023-12-01 13:10:47 25 4
gpt4 key购买 nike

如果我有一个 QDoubleSpinBox 并且有一个名为 setEnabled 的可用方法,它采用 bool 值。如果此值设置为 False,QDoubleSpinBox 将显示为灰色,显示微调按钮内的数字,但不允许用户键入任何内容或与之交互。我想稍微修改一下,以便在未启用 QDoubleSpinBox 时,我希望将 Spin Button 值设置为空字符串或不呈现,并删除显示的任何先前值。

最佳答案

一种可能的解决方案是显示和隐藏 QLineEditQDoubleSpinBox如果QDoubleSpinBox分别启用或禁用。要检测已启用属性的状态更改,您必须重写 changeEvent()方法并验证 QEvent::EnabledChange事件:

import sys

from PyQt5 import QtCore, QtWidgets


class DoubleSpinBox(QtWidgets.QDoubleSpinBox):
def changeEvent(self, e):
if e.type() == QtCore.QEvent.EnabledChange:
self.lineEdit().setVisible(self.isEnabled())
return super().changeEvent(e)


if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)

radiobutton = QtWidgets.QRadioButton("enabled/disabled")
spinbox = DoubleSpinBox()
radiobutton.toggled.connect(spinbox.setDisabled)

w = QtWidgets.QWidget()
lay = QtWidgets.QVBoxLayout(w)
lay.addWidget(radiobutton)
lay.addWidget(spinbox)
w.show()

sys.exit(app.exec_())

enter image description here

enter image description here

关于python - 未启用时将 QDoubleSpinBox 值设置为空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60178714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com