我在一个创建QComboBox
小部件网格的应用程序中遇到了问题(见下图)。我使用for
循环来创建网格元素。你知道吗
QComboBox网格布局
我想能够单独处理每个QComboBox。以下是无需尝试的代码:
grid = QGridLayout()
combos = [
'1', '1', '1', '', '1',
'1', '1', '1', '', '1',
'1', '1', '1', '', '1',
'1', '1', '1', '', '1']
positions = [(i,j) for i in range(5) for j in range(5)]
for position, dcombo in zip(positions, combos):
if dcombo == '':
continue
combo = QComboBox()
for x in range(0, 30):
combo.addItem(QIcon("/icons/%d.PNG" % x),"")
combo.setFixedSize(120,100)
combo.setIconSize(QSize(100,100))
grid.addWidget(combo, *position)
comboList['combo{0}'.format(position)] = position
这是我的尝试,也是我目前所处的困境:
grid = QGridLayout()
combos = [
'1', '1', '1', '', '1',
'1', '1', '1', '', '1',
'1', '1', '1', '', '1',
'1', '1', '1', '', '1']
comboList = {}
positions = [(i,j) for i in range(5) for j in range(5)]
for position, drawcombo in zip(positions, combos):
if drawcombo == '':
continue
combo = QComboBox()
for x in range(0, 30): #
combo.addItem(QIcon("absolver deck reviewer/icons/%d.PNG" % x),"")
combo.setFixedSize(120,100)
combo.setIconSize(QSize(100,100))
grid.addWidget(combo, *position)
comboList['combo{0}'.format(position)] = position
combo.currentIndexChanged.connect(lambda: self.logChange(comboList['combo{0}'.format(position)]))
def logChange(self, currentCombo):
sender = self.sender()
print(str(currentCombo) + ' was changed')
print()方法只返回列表中的最后一个位置(在本例中是(3,4)元组)。你知道吗
stacktrace说明了一切:您只能从UI线程更新UI
使用
runOnUiThread()
查看此link相关问题 更多 >
编程相关推荐