Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am building a QGIS plugin and would like to use a dock widget. I have used QT creator to design the UI, with the object type being a QDockWidget. When the plugin is enabled in QGIS the dockwidget appears to be inside of a normal dialog box. I am therefore unable to dock the plugin to the toolbar space etc. I have looked at other plugins using dock widgets but am unable to spot where I am going wrong. I used the plugin builder to generate my template code.

Result of running my plugin

from PyQt4 import QtCore, QtGui
from ui_Myplugin import Ui_MyPlugin

class MyPluginDialog(QtGui.QDockWidget, Ui_MyPlugin):
    def __init__(self):
        self.ui = Ui_MyPlugin()

part of

class myplugin:

def __init__(self, iface):
    # Save reference to the QGIS interface and map canvas
    self.iface = iface
    self.canvas = iface.mapCanvas()
    self.mapRenderer = self.canvas.mapRenderer()
    # initialize plugin directory
    self.plugin_dir = os.path.dirname(__file__)
    # initialize locale
    locale = QSettings().value("locale/userLocale")[0:2]
    localePath = os.path.join(self.plugin_dir, 'i18n', 'myplugin_{}.qm'.format(locale))

    if os.path.exists(localePath):
        self.translator = QTranslator()

        if qVersion() > '4.3.3':

    # Create the dialog (after translation) and keep reference
    self.dlg = mypluginDialog()

def initGui(self):
    # Create action that will start plugin configuration
    self.action = QAction(
        u"My Plugin", self.iface.mainWindow())
    # connect the action to the run method
    QObject.connect(self.dlg.ui.searchButton, SIGNAL("clicked()"), self.searchFromDialog)
    QObject.connect(self.dlg.ui.zoomButton, SIGNAL("clicked()"), self.zoom)

    self.toolbar = self.iface.addToolBar("My Plugin")
    self.toolbar.setObjectName("PMy Plugin")
    self.toolbarSearch = QLineEdit()
    self.toolbarSearch.setPlaceholderText("Type address and hit enter")

    # Add toolbar button and menu item
    self.iface.addPluginToMenu(u"&My Plugin", self.action)
share|improve this question
up vote 3 down vote accepted

Have a look at this:

The relevant part being:

self.dock = MyPluginDialog()
self.iface.addDockWidget( Qt.RightDockWidgetArea, self.dock )
share|improve this answer
Thanks but I have compiled my UI file to python. I am now unsure how to reference my dock widget (rather than self.dock in the example link)? – Matt Apr 3 '14 at 9:35
... See update ... – Matthias Kuhn Apr 3 '14 at 9:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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