python - how to Activate QLineEdit when QCheckBox pyqt5 qt designer is checked?
问题描述
I just started learning pyqt5 qt designer. I used to use tkinter. I have a problem, and I can't figure out how to do it. As the picture shows, there are QCheckBox and QLineEdit. Keep the LineEdit field 'disabled' when checkbox is not checked; When the CheckBox is checked, I try to get the LineEdit field to be activated in the 'normal' position.
when i use tkinter,
txtSample.configure(state=DISABLED)
txtSample = Checkbutton( text='TEST', variable=var, onvalue=1, offvalue=0,font('arial',16,'bold'))
txtSample = Entry(font=('arial',16,'bold'), bd=8, width=6, justify='left',state=DISABLED)
def checkbuttonSample():
if(var.get() == 1):
txtSample.configure(state=NORMAL)
elif var.get()== 0:
txtSample.configure(state=DISABLED)`
I would use similar code like this.But I couldn't find a solution and I am looking for a solution about this issue. Thank you for your answers in advance.
解决方案
从代码来看非常简单:您需要将toggled
复选框的信号连接到setEnabled()
行编辑的插槽:
self.lineEdit.setEnabled(False)
self.checkBox.toggled.connect(self.lineEdit.setEnabled)
您也可以直接在 Designer 中执行此操作:
- 选择行编辑;
- 在“属性编辑器”面板上,取消选中“启用”选项;
- 进入“编辑信号/槽”模式(从工具栏或“编辑”菜单);
- 在复选框上按下鼠标左键,在行编辑上移动鼠标,然后松开按钮;
- 在随后打开的“配置连接”对话框中,选择左侧的“toggled(bool)”信号,勾选“显示从QWidget继承的信号和插槽”选项,并选择“setEnabled(bool)”插槽,然后点击“确定”;
推荐阅读
- fortran - 如何解决关于使用 Gfortran 将两个多态组件之间的内在赋值为类型变量的问题?
- shell - awk 输入字段分隔符并打印用双引号括起来的所有变量
- sql - 如何在 Teradata SQL 中为不存在的关系“创建”NULL 数据
- c# - Linqpad 图表。Column 和 StackedColumn 的组合
- postgresql - ConstraintViolationException 对 Postgres 的性能有影响吗?
- python-unittest - 如何编写单元测试用例以在 Python 中检查与 SQL 服务器的数据库连接?
- sql - SQL:如何通过知道当前值来找到初始值和每一行的值?
- docker - docker的CI管道?
- javascript - 将 onclick 弹出框显示到特定 id
- r - 枚举 data.table 中组内的组