Hi, 
thanks for the answer. I did other tests But without success. 

I tried this code:

   def formOpen(dialog, layerid, featureid):
       widg = dialog.findChild(QgsRelationReferenceWidget, 'fk_via_cod');

       msgBox = QMessageBox()
       msgBox.setText(str(widg))
       msgBox.exec_()

And the message box returns None as widget type

Then I tried this:

   def formOpen(dialog, layerid, featureid):
      widg = dialog.findChild(QgsRelationReferenceWidget(), 'fk_via_cod');

      msgBox = QMessageBox()
      msgBox.setText(str(widg.foregeinKey()))
      msgBox.exec_()

it returns:
TypeError: QgsRelationReferenceWidget(QWidget): not enough arguments


Then I tried to specified the widget as QWidget o QComboBox:

  def formOpen(dialog, layerid, featureid):
      widg = dialog.findChild(QgsRelationReferenceWidget(QWidget), 
'fk_via_cod');

      msgBox = QMessageBox()
      msgBox.setText(str(widg.foregeinKey()))
      msgBox.exec_()

It returns:
TypeError: QgsRelationReferenceWidget(QWidget): argument 1 has unexpected type 
'PyQt4.QtCore.pyqtWrapperType'


So I tried to use QgsRelationReferenceWidgetWrapper() instead of  
QgsRelationReferenceWidget():

def formOpen(dialog, layerid, featureid):
    widg = dialog.findChild(QgsRelationReferenceWidget(QWidget), 
'fk_via_cod');

    msgBox = QMessageBox()
    msgBox.setText(str(widg.foregeinKey()))
    msgBox.exec_()

It returns:
TypeError: QgsRelationReferenceWidgetWrapper(QgsVectorLayer, int, QWidget, 
QgsMapCanvas, QgsMessageBar, QWidget parent=None): argument 1 has unexpected 
type 'PyQt4.QtCore.pyqtWrapperType'


I don't understand how get the widget type. Where is the mistake?

If I change the edit widget properties for the field in "relation value" 
instead of "Relation Reference", so I can use this code to recover the foregien 
key:

def formOpen(dialog, layerid, featureid):
    widg = dialog.findChild(QCombobox, 'fk_via_cod');

    msgBox = QMessageBox()
    msgBox.setText(str(widg.itemData(widg.currentIndex())))
    msgBox.exec_()


Regards

Enrico Fiore

----Messaggio originale----
Da: [email protected]
Data: 07/04/2015 17.52
A: <[email protected]>
Ogg: Re: [Qgis-developer] Access to the value in a Relation reference wiget

 You try get a QgsRelationReferenceWidget (in qgis.gui) (not sure though if 
specifying this explicitly makes any difference in python though, it should 
determine the real type anyway).
 
 The methods you are looking for are then
 
 setForeignKey()
http://qgis.org/api/classQgsRelationReferenceWidget.
html#a2e9fb74545d2bb4b697a88ca4e434600
 
 and
 
 foreignKey()
http://qgis.org/api/classQgsRelationReferenceWidget.
html#af1765af438f3dd4e642334a338a03ca4
 
 Best,
 Matthias
 
 On 04/07/2015 10:47 AM, Enrico Fiore wrote:
  Hi,
 I am trying to acces to the value stored in a field defined as Relation 
Reference widget, I tried this code:
 
     dialog.findChild(QWidget,"fk_via_cod")
 
 so I access to the object but not to the value.
 
 I need to do something like this
      nameFieldDir = dialog.findChild(QLineEdit,"cod_direzione")
 
 How I can perform this?
 
 Regards
 
 Enrico Fiore
 
 
 
 
 
  
 _______________________________________________Qgis-developer mailing 
[email protected]http://lists.osgeo.org/mailman/listinfo/qgis-
developer
  
 


_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to