1

I have created a plugin which first shows login window and then user needs to enter details and press submit. After details are verified at back-end, a new window appears with buttons for different tasks.

I wish to have this window appear as a toolbar on the right side in QGIS by default such that the user do not need to move this window again and again.

For example, below is AutoField Plugin Window on the right side of QGIS:

Plugin

I have tried to do the same with below code:

dock_widget = QDockWidget(self.iface.mainWindow())
dock_widget.setWidget(MainWindow) dock_widget.setFixedWidth(356)
dock_widget.setFixedHeight(600)
self.iface.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock_widget)

However, half of the bottom of this toolbar appears blank. How to have this toolbar fixed with particular size on the right hand side?

  • 1
    If you were using dockwidgets, you could use something like self.iface.addDockWidget(Qt.RightDockWidgetArea, self.myDockWidget) – Joseph Mar 8 at 10:20
  • @Joseph Perfect, that works like a charm. Just want to know when I use the below code: dock_widget = QDockWidget(self.iface.mainWindow()) dock_widget.setWidget(MainWindow) dock_widget.setFixedWidth(356) dock_widget.setFixedHeight(600) self.iface.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock_widget) It takes up the all the space including the one which is unused (bottom right). How to have it with a particular height only? – Sajjadmanal Mar 8 at 11:16
  • If I understand you correctly, there is only one right-dockwidget panel so the whole panel will be shown regardless of the size of the dockwidget. So if your dockwidget only filled half the panel, the other half will still have to be shown. The only reason why you would set the height would be if you wanted to add multiple dockwidgets to the right panel and one dockwidget had more items in it then you would probably want to set the height of that one to be greater than the other. – Joseph Mar 8 at 11:29
  • @Joseph There is only one right-dockwidget panel and hence, the whole panel is shown. But I don't want that unused half panel to be shown. What can be done in this case? – Sajjadmanal Mar 8 at 12:04
  • Unfortunately, I don't think there is much you can do in this case. – Joseph Mar 8 at 12:22
1

If you were using dockwidgets, you could use something like the following:

self.iface.addDockWidget(Qt.RightDockWidgetArea, self.myDockWidget)

As mentioned in the comments, the whole dockwidget area needs to be filled so it won't be possible for you to set a fixed height, only the width.

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.