0

I am trying to build the equivalent of an ArcMap Toolbar in PyQGIS. My toolbar has interactive functionality. For example, in the toolbar below, I cannot access any edit functions until I have selected a certain raster id. Each button has a different purpose and I still need to be able to draw polygons on the map canvas. I need a similar functionality in my QGIS version.

I also need to be able to override some standard QGIS functionality such as some forms when saving layer edits ( I understand that I can do this using slots and signals)

enter image description here

Currently I have come across 2 different methods of trying to replicate this in QGIS:

  1. Create a plugin for each button using the QGIS Plugin Builder and Qt Designer and then group my plugins into a toolbar using a Custom Toolbar Plugin. Although this is what I need aesthetically, it doesn't allow interactivity between my plugins(???)

  2. Use PyQt to build a toolbar from scratch. Although I think this will give me the functionality I need, it seems to be far more convoluted and as soon as I click off the toolbar it disappears- I need it to be present at all times.

Can anyone advise on what the best method to approach this problem is? I.e. what is the best method to get full interactivity between the different buttons/plugins and yet group them together as a toolbar?

I am using QGIS 3.4 and PyQt5

  • 2
    Don't fully understand the issues you're facing. For sure, option 2 is the way to go. What do you mean by "as soon as I click off the toolbar it disappears"? Look at this GIF, it's a single plugin. – Germán Carrillo Mar 31 at 22:48
  • Hi @GermánCarillo . I mean that I have a script which generates the window. However as soon as I click off the toolbar window, it disappears and I have to rerun the script to generate it again. Is there a source for that GIF? ... it would really help if I could see an example :) – thesunnyscientist Apr 1 at 9:04
  • 1
    For sure, I also added a link to the source plugin in the first comment, you can look at it and reuse the code. Have a look at this answer to add toolbars and menus to QGIS, the rest would be PyQt5 (adding buttons to a toolbar, adding menus to a toolbar, etc.). – Germán Carrillo Apr 1 at 13:29
  • Thank you- this has helped me hugely ! :) – thesunnyscientist Apr 1 at 14:05
  • I'll condense the comments as an answer, perhaps adding more details. Just need to have some time :) – Germán Carrillo Apr 1 at 14:24

Your Answer

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

Browse other questions tagged or ask your own question.