【问题标题】:How to search for a specific kind of qt gui control如何搜索特定类型的 qt gui 控件
【发布时间】:2015-04-08 16:26:09
【问题描述】:

我有一个QWidget,其中包含一个QGroupBox,其中包含QComboBoxQLineEditQCheckBox

我需要遍历所有控件,如果控件是QCheckBox,询问是否勾选。我需要知道如何检查所有 QCheckBox - 这个想法可能是这样的:

count = 0
for control in groupbox.controls():
    if control is type of QtGui.QCheckBox:
        if control.isChecked:
            count = count + 1
        else:
            print('no checked')
    else:
        print('no QtGui.QCheckBox')
print ('there are '+ str(count)+ 'checked')

【问题讨论】:

    标签: python-2.7 pyqt iteration state qcheckbox


    【解决方案1】:

    如果复选框都是 groupbox 的子项,那么你可以试试这个:

    count = 0
    for checkbox in groupbox.findChildren(QtGui.QCheckBox):
        if checkbox.isChecked():
            count += 1
    print('there are %s checked' % count)
    

    如果它们是这样创建的,复选框将是 groupbox 的子项:

    checkbox = QtGui.QCheckBox('Title', groupbox)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多