[PyQt] QComboBox and QVariant in pyqt4 ?

alteo_gange romanocaldoni at free.fr
Wed Nov 7 16:07:46 GMT 2007


Hi,

I try to include an personal identify (or key) in ComboBox items. I've thought 
to use QVariant:

------------------------------------

#!/usr/bin/python
# -*- coding: Utf-8 -*-

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class Widget(QWidget):
	def __init__(self):
		QWidget.__init__(self)
		
		hbox=QHBoxLayout()
		combo = QComboBox()
		lst=[("a",0),("b",1),("c",2),("d",3),("e",4)]
		for i in lst:
			combo.addItem(i[0],QVariant(i[1]))
		hbox.addWidget(combo)
		self.connect(combo,SIGNAL("activated(QString, QVariant"),self.changeItem)
		self.setLayout(hbox)
	
	def changeItem(self,i,j):
		print i,j

app = QApplication(sys.argv)
main = Widget()
main.show()
sys.exit(app.exec_())

-------------------------------------

But it doesn't work. changeItem() is never called because of the 
signal "activated(QString, QVariant)".

QComboBox and QVariant in pyqt4: Is this possible?

-- 
alteo_gange



More information about the PyQt mailing list