1

I am relatively new to PyQGIS and struggling to convert my simple code into a plugin class. The code works when run from the Python window, but when I add it to def run(self): I get an error. I am trying to get the plugin to display the GPSInformation window.

def run(self):
    for x in iface.mainWindow().findChildren(QDockWidget):
        if x.objectName() == 'GPSInformation':
            x.setVisible(False)

The error says NameError: name 'QDockWidget' is not defined

1 Answer 1

3

You need to import the QDockWidget using

from qgis.PyQt.QtWidgets import QDockWidget

You may also consider using self.iface.mainWindow() instead of iface.mainWindow() if you have declared it this way in your plugin. Normally when creating a new plugin, it's already declared this way. You can also shortened your code with iface.mainWindow().findChildren(QDockWidget, 'GPSInformation')

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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