I'm trying to get to know how to make my own widgets to be used in the Edit Widget. I have looked at this plugin here and it is very usefull: https://github.com/elpaso/qgis-formawarevaluerelationwidget
I'm trying to make a custom widget which will have a combobox and a few small buttons (like flash feature, zoom to, pan to)
In the example i have created from the form aware relation widget i can succesfully create a combobox.
class FormToolsRelationWidgetWrapper(QgsEditorWidgetWrapper): def __init__(self, vl, fieldIdx, editor, parent): """ QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent """ some init stuff here... def createWidget(self, parent): #self.mComboBox = TestWidget(parent) #self.mComboBox = TestWidget() self.mComboBox = QComboBox(parent) QObject.connect( self.mComboBox, SIGNAL( "currentIndexChanged( int )" ), self, SLOT( "valueChanged()" ) ) return self.mComboBox
The result is this:
Looks very good. And i know i have not yet populated the combobox with data.
If i instead activate a widget i have created with this code (with TestWidget(parent) ):
class TestWidget(QWidget): def __init__(self, parent=None): super(TestWidget, self).__init__(parent) # create a combobox combobox_1 = QComboBox(self) combobox_1.addItem("Item 1") # create a combobox with a parent widget combobox_2 = QComboBox(self) combobox_2.addItem("Item A") combobox_2.addItem("Item B") combobox_2.addItem("Item C") # layout layout = QHBoxLayout(self) layout.addWidget(combobox_1) layout.addWidget(combobox_2) layout.addStretch() # sets the layout self.setLayout(layout)
I'm not sure what is wrong. I have test by not assigning QComboBox and QHBoxLayout to self. Without any luck. Here the widget does not replace the ID field. i thought this would be replaced with my widget. Like the example with qcombobox.
Any suggestions to make this work?
I can not find any examples/tutorials explaning this. Maybe if it get this sorted i will make a small introduction to this.