I am trying to write a plugin with a input control such as textbox on it. I looked around quite a bit for building plugins. But I can only find examples of how to build a plugin with buttons/icons in its toolbar.
How can I add other widgets such as a textbox on my plugin's toolbar?
For the button, there isn't much to handle except for a callback when it's clicked. I imagine it would be quite different for a textbox as one needs to associate the input control to e.g. a global variable??
For now, I need interaction with the textbox (
QLineEdit). I want to implement a plugin for going to the next feature where I can display the row number of the current record, and jump to any given row by entering its row number.
I am using QGIS2.99 and Qt5, the standard
Plugin Builder and
deploy the plugin template. I suppose I need to add the
initGui() of the main
py file(as shown below). I don't know much about Qt5, and only figured I might need
addUserInputWidget() and/or connect it with the
add_action() function? But I don't know how to put the pieces together, and register the events etc.
Here is what I have so far:
def initGui(self): """Create the menu entries and toolbar icons inside the QGIS GUI.""" # Create & add a textbox self.textbox = QLineEdit(self.iface.mainWindow()) self.textbox.resize(80,20) self.txtAction = self.toolbar.addWidget(self.textbox) #should I use addUserInputWidget(self.textbox) #?? self.txtAction.setToolTip(self.tr(u'Current Row Number')) #callback=self.runTextChange how to register an event handler?
The UI shows but there is no interaction.
Can someone help explain how to link the
QLineEdit to the toolbar so that I can get/change the text value?
Also, a minor issue I can't figure out is that the textbox takes up the full width of the toolbar no matter what I use in its
.resize() method. How should I limit its width?