2

I am working on a plugin to display and interact with graphics, which are visible in the view and layout.

Form annotations are a great alternative for this.

The form annotations (QgsFormAnnotation) receive the path to a .uic file and display the widget.

Is it possible to access the widget through PyQGIS, so I can add controls, and handle events?

0

1 Answer 1

6

My understanding of QgsFormAnnotation class is there is no way to set form (Qt Designer UI) other than by using function setDesignerForm which sets it from file path given.

So to do adjustments to the form used for annotation you have to either create new ui file or edit existing, and set the path to it via setDesignerForm function.

As the ui file is standard xml file you can read/write these files from your plugin using python xml library.

If you need dynamic interactive form, it should be part of your plugin UI - as dialog or dock widget, which can be responsive (connected) to signals coming from all parts of QGIS. E.g. use QgsMapCanvas.selectionChanged to update your dock widget UI (form) with any selection change in any layer in map canvas.

2
  • Thanks Miró apparently it is as you say, I am looking into several options, is it possible to write a custom widget definition to a .ui file?
    – Luis Perez
    Commented Oct 21, 2021 at 12:24
  • 1
    I can't see why not, but I am not sure I follow where are you going with all this. Form annotation is just extension to basic annotation, the content is not meant to be interactive, it is just to allow to use QT elements to be able to generate annotation content based on underlying data, and give some desired 'form' to content. Maybe if you can be more specific with what/why you want to achieve...
    – Miro
    Commented Oct 22, 2021 at 12:46

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.