[PyQt] pyQT -python beginner question - combo box signal	function call
    karsten vennemann 
    karsten at terragis.net
       
    Sat Apr 23 03:19:21 BST 2011
    
    
  
Thanks for all the input I received 
I found one seemingly good solution (via internet search) that works using
functools.partial  that is available since python 2.5
http://docs.python.org/library/functools.html#functools.partial
My code is then
...
from functools import partial
...
QObject.connect(comboBoxNew[dropbox_counter],SIGNAL("currentIndexChanged(QSt
ring)"),partial(self.changeValue, x = dropbox_counter))
    def changeValue(self, value, x):                  
        mc = self.canvas                              
        layer = mc.currentLayer()                     
        ob = layer.selectedFeaturesIds()              
        layer.changeAttributeValue(int(ob[0]),x,value)
Hopefully that helps someone else too when trying to easily pass an
additional parameter  from an QT signal slot ...
Karsten 
_______________________
From: C. B. Esquire [mailto:crackerbunny at gmail.com] 
Sent: Friday, April 22, 2011 18:51
To: karsten vennemann
Subject: Re: [PyQt] pyQT -python beginner question - combo box signal
function call
	Perhaps use the currentIndex() method on the combobox inside your
changeValue function ...
	
	def changeValue(self, value):
	    mc = self.canvas
	    layer = mc.currentLayer()
	    obj= layer.selectedFeatureIds()
	    layer.changeAttributeValue(int(obj[0],
yourComboBox.currentIndex(), value)
	
	
	You can also use a not very highly recommend way, with lambda,
however it sucks for garbage cleanup, it's sloppy python,and you will no
longer get your QString passed.... off the top of my head it would be
something like ....
	
	
QObject.connect(comboBoxNew[dropbox_counter],SIGNAL("currentIndexChanged(QSt
ring)"), lambda: self.changeValue(self, dropbox_counter))
	
	
	
	
	On Fri, Apr 22, 2011 at 8:07 PM, karsten vennemann
<karsten at terragis.net> wrote:
	
		I have a dynamic data entry from to which I am adding combo
boxes on he fly using lists
		 
		  # here I add labels and combo boxes to the form from a
list ..
	
self.dlg.ui.streamEditCustomFormLayout.addWidget(comboBoxNewLabel[dropbox_co
unter])
	
self.dlg.ui.streamEditCustomFormLayout.addWidget(comboBoxNew[dropbox_counter
])
		
		# and then add a signal to trigger updating of the attribute
in a table with the value selected in the combo box via the changeValue
function
	
QObject.connect(comboBoxNew[dropbox_counter],SIGNAL("currentIndexChanged(QSt
ring)"),self.changeValue)
		
		the function I have works but so is set to change always
attribute column 2 (in bold)
		
		    def changeValue(self, value):
		        mc = self.canvas                  # the map cabavs
uin QGIS
		        layer = mc.currentLayer()      # a layer in QGIS
		        ob = layer.selectedFeaturesIds()   
		        layer.changeAttributeValue(int(ob[0]),2,value)  #
Change value for colum 2 
		 
		How can I add one additional parameter to the function call
form the combo box ?
		 
		 
		Something like
		 
	
QObject.connect(comboBoxNew[dropbox_counter],SIGNAL("currentIndexChanged(QSt
ring)"),self.changeValue(self, dropbox_counter))
		 
		    def changeValue(self, value, colum_id):
		        mc = self.canvas         
		        layer = mc.currentLayer()
		        ob = layer.selectedFeaturesIds()
	
layer.changeAttributeValue(int(ob[0]),colum_id,value)
		 
		 
		but with this I am getting
	
QObject.connect(comboBoxNew[dropbox_counter],SIGNAL("currentIndexChanged(QSt
ring)"),self.changeValue(self, dropbox_counter))
		TypeError: arguments did not match any overloaded call:
		  QObject.connect(QObject, SIGNAL(), QObject, SLOT(),
Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type
'NoneType'
		  QObject.connect(QObject, SIGNAL(), callable,
Qt.ConnectionType=Qt.AutoConnection): argument 3 has unexpected type
'NoneType'
		  QObject.connect(QObject, SIGNAL(), SLOT(),
Qt.ConnectionType=Qt.AutoConnection): argument 2 has unexpected type 'str'
				 
		How can this be done correctly ?
		Karsten
		_______________________________________________
		PyQt mailing list    PyQt at riverbankcomputing.com
		http://www.riverbankcomputing.com/mailman/listinfo/pyqt
		
    
    
More information about the PyQt
mailing list