0

I was looking for a way to add a panel and I found QDockWidget but I don't seem to find the way to add a new panel since examples I've seen use a Qgis tool to create these panels or use QDockWidgetto show or hide existent panels by their name.

So the question is: How could I add a custom QDockWidget as a Qgis Panel with the content I tell it to load?

This is the way I've been able to create it, it can only be appended to the plugin's interface.

Not like this

I want it to be placed in the Qgis interface like this one:

It Should be like this

2

You can use the method addDockWidget from the QgisInterface: https://qgis.org/api/classQgisInterface.html#ad2c81fbbe55bc9609af7a36e56d6857f

When you have your iface object, or from from qgis.utils import iface, you can do:

iface.addDockWidget(Qt.RightDockWidgetArea, your_dock_object)

to add your dock widget on the right area.

| improve this answer | |
  • This helps me position a DockWidget but what about setting a dock_object, how is it done? – Thriskel Nov 23 '18 at 20:06
  • What do you mean with dock_object? Do you refer to the your_dock_object in my snippet? It's a object from the class QDockWidget. – etrimaille Nov 23 '18 at 23:11
  • yes I tried to create one and I did it but it was placed inside the plugin's interface, and I need it inside Qgis' interface, but I'm really struggling to understand this one... – Thriskel Nov 26 '18 at 13:09
  • I'm not sure to understand what you mean, maybe you can update your question with some screenshots. You can have a look to the InaSAFE plugin, it has a dock. Is-it what you want? – etrimaille Nov 26 '18 at 14:11
  • 1
    It's what InaSAFE is doing docs.inasafe.org/en/_images/run_basic_00.png and what I suggested you to use iface.addDockWidget(Qt.RightDockWidgetArea, your_dock_object). You need to check where you are adding your dock in your plugin window, remove this line and use the snippet I pasted instead. – etrimaille Nov 27 '18 at 11:58

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.