I set up a QgsFieldComboBox
for a Plugin. I know I can read the selected fieldname the following:
self.dlg.MyQgsFieldComboBox.currentField()
Studying the docs, I cannot find an option to read the currentFieldType() directly. So I know I can get field types of my selected layer the following:
self.mylayerfieldtypes = [field.typeName() for field in self.myselectedlayer.fields()]
I could stitch this together the following, to get the field type only of my selected field:
myfieldname = self.dlg.MyQgsFieldComboBox.currentField()
for field in self.myselectedlayer.fields():
if field.name() == myfieldname:
myfieldtype = field.typeName()
But my issue now is, when creating a new layer having a field with the same type as my selected field, I cannot just use myfieldtype
for it like
QgsField("MyNewFieldHavingTheSameTypeAsMyOldField", myfieldtype)
How can I create a new field, having the same type as my selected field? Copying the field to my new layer is not an option.