QgsQmlWidgetWrapper class

Wraps a QQuickWidget to display QML code.

Base classes

class QgsWidgetWrapper
Manages an editor widget Widget and wrapper share the same parent.

Constructors, destructors, conversion operators

QgsQmlWidgetWrapper(QgsVectorLayer* layer, QWidget* editor, QWidget* parent)
Create a qml widget wrapper.

Public functions

auto createWidget(QWidget* parent) -> QWidget* override
This method should create a new widget with the provided parent.
void initWidget(QWidget* editor) override
This method should initialize the editor widget with runtime data.
void reinitWidget()
Clears the content and makes new initialization.
void setQmlCode(const QString& qmlCode)
writes the qmlCode into a temporary file
auto valid() const -> bool override
Returns true if the widget has been properly initialized.

Function documentation

QgsQmlWidgetWrapper::QgsQmlWidgetWrapper(QgsVectorLayer* layer, QWidget* editor, QWidget* parent)

Create a qml widget wrapper.

Parameters
layer The layer on which the feature is
editor An editor widget. Can be NULL if one should be autogenerated.
parent A parent widget

QWidget* QgsQmlWidgetWrapper::createWidget(QWidget* parent) override

This method should create a new widget with the provided parent.

Parameters
parent You should set this parent on the created widget.
Returns A new widget

This will only be called if the form did not already provide a widget, so it is not guaranteed to be called! You should not do initialization stuff, which also has to be done for custom editor widgets inside this method. Things like filling comboboxes and assigning other data which will also be used to make widgets on forms created in the QtDesigner usable should be assigned in initWidget().

void QgsQmlWidgetWrapper::initWidget(QWidget* editor) override

This method should initialize the editor widget with runtime data.

Parameters
editor The widget which will represent this attribute editor in a form.

Fill your comboboxes here.

bool QgsQmlWidgetWrapper::valid() const override

Returns true if the widget has been properly initialized.

Returns Validity status of this widget.

This acts as hint for the calling party if this wrapper can be used after initializing it. If it cannot be used this is a hint to the caller that he may try to find another suitable widget type instead.