Python 如果列的1没有任何值,则隐藏QTableWidget中的行

Python 如果列的1没有任何值,则隐藏QTableWidget中的行,python,pyqt,maya,qtablewidget,qcombobox,Python,Pyqt,Maya,Qtablewidget,Qcombobox,我想对我编写的部分代码发表一些意见。我的UI由一个QTableWidget组成,其中有两列,其中一列用QComboBox填充 对于第一列,它将使用在场景中找到的角色装备列表(完整路径)填充单元格,而第二列将为每个单元格创建一个Qcombobox,并填充颜色选项,因为该选项来自json文件 现在,我正在尝试创建一些单选按钮,为用户提供显示所有结果的选项,或者如果Qcombobox中没有特定行的颜色选项,它将隐藏这些行 正如您在我的代码中所看到的,我正在填充每列的数据,因此,当我尝试输入if not

我想对我编写的部分代码发表一些意见。我的UI由一个
QTableWidget
组成,其中有两列,其中一列用
QComboBox
填充

对于第一列,它将使用在场景中找到的角色装备列表(完整路径)填充单元格,而第二列将为每个单元格创建一个
Qcombobox
,并填充颜色选项,因为该选项来自json文件

现在,我正在尝试创建一些单选按钮,为用户提供显示所有结果的选项,或者如果
Qcombobox
中没有特定行的颜色选项,它将隐藏这些行

正如您在我的代码中所看到的,我正在填充每列的数据,因此,当我尝试输入
if not len(new_sub_name)==0:
时,虽然它没有输入任何带有零选项的
Qcombobox
,但如何隐藏
Qcombobox
中没有选项的行

def populate_table_data(self):
    self.sub_names, self.fullpaths = get_chars_info()

    # Output Results
    # self.sub_names : ['/character/nicholas/generic', '/character/mary/default']
    # self.fullpaths : ['|Group|character|nicholas_generic_001', '|Group|character|mary_default_001']

    # Insert fullpath into column 1
    for fullpath_index, fullpath_item in enumerate(self.fullpaths):
        new_path = QtGui.QTableWidgetItem(fullpath_item)
        self.character_table.setItem(fullpath_index, 0, new_path)
        self.character_table.resizeColumnsToContents()

    # Insert colors using itempath into column 2
    for sub_index, sub_name in enumerate(self.sub_names):
        new_sub_name = read_json(sub_name)

        if not len(new_sub_name) == 0:
            self.costume_color = QtGui.QComboBox()
            self.costume_color.addItems(list(sorted(new_sub_name)))
            self.character_table.setCellWidget(sub_index, 1, self.costume_color)
可以使用隐藏行。至于代码的其余部分,我看不出您当前的代码有什么错误,但FWIW我会这样写(当然,完全未经测试):


嘿,谢谢,但有关于我如何填充数据的见解吗?@disbia。我不知道它对你有多有用,但我已经扩展了我的答案。我一定会检查它,忘记带我的代码回家。但即便如此,我能问一下为什么将
(sub_name,fullpath)
括在一起吗?我想这只是优化和缩短我的代码?@disbia。括号是元组展开所必需的。我忘了把
枚举
放在那里,所以这可能不明显。
def populate_table_data(self):
    self.sub_names, self.fullpaths = get_chars_info()
    items = zip(self.sub_names, self.fullpaths)
    for index, (sub_name, fullpath) in enumerate(items):
        new_path = QtGui.QTableWidgetItem(fullpath)
        self.character_table.setItem(index, 0, new_path)
        new_sub_name = read_json(sub_name)
        if len(new_sub_name):
            combo = QtGui.QComboBox()
            combo.addItems(sorted(new_sub_name))
            self.character_table.setCellWidget(index, 1, combo)
        else:
            self.character_table.setRowHidden(index, True)

    self.character_table.resizeColumnsToContents()