我想对我写的代码的一部分有一些看法。我的UI由一个QTableWidget
组成,其中有2列,其中2列中的一列填充了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)
可以使用setRowHidden隐藏行。至于其余的代码,我看不出你现在的代码有什么问题,但是我会写这样的代码(当然,完全没有经过测试):
相关问题 更多 >
编程相关推荐