我想知道在PySide中将可点击项添加到QComboBox()的最佳方式是什么?
到目前为止我的组合框功能。
def setTreeWidgetsComboBox(self, index, items, currVariation, node=None):
mainComboBoxWidget = QtGui.QWidget()
mainComboBoxLayout = QtGui.QVBoxLayout()
self.decayComboBox = QtGui.QComboBox()
mainComboBoxLayout.addWidget(self.decayComboBox)
mainComboBoxLayout.setContentsMargins(0,0,0,0)
mainComboBoxWidget.setLayout(mainComboBoxLayout)
if len(items) != 1:
for x in items:
try:
i = x.split('_')[1]
except:
i = x
continue
self.decayComboBox.addItem(i)
else:
self.decayComboBox.addItem(items[0])
i = self.decayComboBox.findText(currVariation, QtCore.Qt.MatchFixedString)
if i >= 0:
self.decayComboBox.setCurrentIndex(i)
self.decayComboBox.addItem('new variation..')
self.decayComboBox.setFixedHeight(20)
self.nmcTableWidget.setIndexWidget(index, mainComboBoxWidget)
return self.decayComboBox
i = self.decayComboBox.findText(currVariation, QtCore.Qt.MatchFixedString)
if i >= 0:
self.decayComboBox.setCurrentIndex(i)
self.decayComboBox.addItem('new variation..')
self.decayComboBox.setFixedHeight(20)
self.nmcTableWidget.setIndexWidget(index, mainComboBoxWidget)
return self.decayComboBox
现在我想要新的变种。'进入点击事件。 我是否必须使用自定义委托覆盖整个QComboBox类,或者是否有某种方法将条目添加为QComboBox小部件并使其单击。连接?
抱歉,如果这是一个基本问题。我在PySide中还不是很先进。 谢谢。答案 0 :(得分:0)
当然currentIndexChanged就是这个伎俩。