2

I try to customize the QgsFieldExpressionWidget. But if I open the Expression Dialog, the "Fields and Values" are empty. What I am missing?

lay= iface.activeLayer()
wid = QgsFieldExpressionWidget()
wid.setLayer=lay
scope= QgsExpressionContextUtils.layerScope(lay)# QgsExpressionContextScope()
scope.setFields (lay.fields())
wid.appendScope(scope)
wid.registerExpressionContextGenerator (lay)#QgsProject().instance())
wid.expressionDialogTitle="Test"
wid.setExpression('Foto IS NULL')
wid.show()
print (wid.currentText())
The Rabbit
  • 556
  • 2
  • 15

1 Answers1

1

setLayer is a method ,not variable.Change only this for show fields

wid.setLayer(lay)
Fran Raga
  • 7,838
  • 3
  • 26
  • 47