[QGIS-Developer] Create a custom python based widget to be used in attribute forms

Matthias Kuhn matthias at opengis.ch
Mon Apr 6 04:00:35 PDT 2020


Hi Bo,

I once wrote an article (7 years ago) but it has disappeared from the 
earth surface unfortunately. And the internet archive "is having issues 
momentarily".

What you need to do is to:

- subclass QgsEditorWidgetWrapper --> 
https://qgis.org/pyqgis/3.0/gui/Editor/QgsEditorWidgetWrapper.html

- and create a subclass of QgsEditorWidgetFactory and register it in the 
editor widget registry --> 
https://qgis.org/pyqgis/3.0/gui/Editor/QgsEditorWidgetFactory.html

- let yourself inspire from the existing implementations - although C++ 
(e.g. a simple text edit widget 
https://github.com/qgis/QGIS/blob/master/src/gui/editorwidgets/qgstexteditwrapper.cpp)

Hope this helps and have fun

Matthias


On 4/5/20 10:48 AM, Bo Victor Thomsen wrote:
> (Sorry about the hijacking of another thread)... Here is my question 
> (again...)
>
> Hi List -
>
> I remember (very vaguely) an blog-article describing how to make a
> custom pyqt widget to use in QGIS attribute forms.
>
> I'm not talking about designing a custom form with python logic (I know
> how do that) but making a custom widget as a replacement for one of the
> build-in widget like calendar or value-relation widgets a.o.
>
> My goal is to make a widget based on a qtreeview or qtreewidget that is
> populated using a layer with three columns "parent", "key" and "value",
> where "parent" is used to build the tree structure.
>
> Something like the existing value-relation widget but with a treewidget
> instead of a combobox, that can be used to create multi step
> "drill-down" functionality.
>
> However, I can't find the article. Is there anyone on this mailing-list,
> that can point me in the right direction ?
>
> (The correct course of action would be to program it in C++. However I
> can't find the time - or intellectual energy -  to brush up my very
> rusty knowledge of C++ :-/)
>


More information about the QGIS-Developer mailing list