I am following the tutorial found here for developing a simple QGIS plugin within QGIS 2.0.1 installed on Windows 7. However, as I have began to try developing a link between the GUI and each the mouse click of the map canvas, the main plugin code does not seem to recognize the fields in the GUI.

To illustrate with the example in the tutorial. Within in my plugin.py code I have the function:

class vector_selectbypoint:
     def __init__(self, iface):
         # Save reference to the QGIS interface
         self.iface = iface
         # refernce to map canvas
         self.canvas = self.iface.mapCanvas()
         # out click tool will emit a QgsPoint on every click
         self.clickTool = QgsMapToolEmitPoint(self.canvas)
         # create our GUI dialog
         self.dlg = vector_selectbypointDialog()    

    def handleMouseDown(self, point, button):
         self.dlg.setTextBrowser( str(point.x()) + " , " +str(point.y()) )

that simply writes the lat and long into a TextBrowser with the GUI by calling the clearTextBrowser and setTextBrowser functions in a seperate pluginDialog.py script where the following code is ran:

class vector_selectbypointDialog(QtGui.QDialog, Ui_vector_selectbypoint):
    def __init__(self):
        self.ui = Ui_vector_selectbypoint()

    def setTextBrowser(self, output):

    def clearTextBrowser(self):

which interacts with the ui_plugin_ui.py where txtFeedback is the TextBrowser in the GUI. Below is a snippet of the ui_plugin_ui.py file:

class Ui_vector_selectbypoint(object):
    def setupUi(self, vector_selectbypoint):
        vector_selectbypoint.resize(400, 300)
        self.buttonBox = QtGui.QDialogButtonBox(vector_selectbypoint)
        self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))
        self.chkActivate = QtGui.QCheckBox(vector_selectbypoint)
        self.chkActivate.setGeometry(QtCore.QRect(20, 250, 81, 20))
        self.txtFeedback = QtGui.QTextBrowser(vector_selectbypoint)
        self.txtFeedback.setGeometry(QtCore.QRect(80, 20, 221, 151))

The issue is that when I run the plugin in QGIS and click on the map canvas the following error is thrown:

AttributeError: 'ui_plugin_ui' object has no attribute 'txtFeedback'

I have verified that there are no syntax issues but the issue persists. If anyone has any insight I would eternally grateful!

  • Please provide the code for your class definition and your init method – gsherman Apr 16 '14 at 14:01
  • see the above the edits and let me know if I can clarify further. Thank you! – user2593375 Apr 16 '14 at 16:19

Since your vector_selectbypoint class inherits from the UI class, get rid of:

self.ui = Ui_vector_selectbypoint()

You can then refer to the text browser using:


The way your code is now, you are setting self.ui to your UI but never setting it up. That would require using:


rather than

  • That did the trick, thank you! I suppose that is the danger when you use out-of-the-box code, and it doesn't help matters that I am rather dense when it comes to GUI development. – user2593375 Apr 17 '14 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.