繁体   English   中英

如果pyqt5中的ComboBox中有项目,如何启用按钮?

[英]How to Enable Button if there is Item in ComboBox in pyqt5?

图片中的问题

嗨,在这张图片中,我想在组合框中出现 USB 名称时启用开始按钮,如果名称没有出现,按钮应该自动禁用,这是我的代码。

def x(self):
      if (self.comboBox_3.currentIndex() == -1):
          self.pushButton_5.setEnabled(False)
      else:
          self.pushButton_5.setEnabled(True)

您必须使用 currentIndexChanged 信号来评估该逻辑:

    # __init__ method
    # ...
    self.comboBox_3.currentIndexChanged[int].connect(self.on_currentIndexChanged)

def on_currentIndexChanged(self, index):
    self.pushButton_5.setEnabled(index != -1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM