QgsFieldComboBox class

The QgsFieldComboBox is a combo box which displays the list of fields of a given layer.

It might be combined with a QgsMapLayerComboBox to automatically update fields according to a chosen layer. If expression must be used, QgsFieldExpressionWidget shall be used instead.

Constructors, destructors, conversion operators

QgsFieldComboBox(QWidget* parent = nullptr) explicit
QgsFieldComboBox creates a combo box to display the fields of a layer.

Public functions

auto allowEmptyFieldName() const -> bool
Returns true if the combo box allows the empty field ("not set") choice.
auto currentField() const -> QString
Returns the currently selected field.
auto filters() const -> QgsFieldProxyModel::Filters
currently used filter on list of fields
auto layer() const -> QgsVectorLayer*
Returns the layer currently associated with the combobox.
void setAllowEmptyFieldName(bool allowEmpty)
Sets whether an optional empty field ("not set") option is shown in the combo box.
void setFilters(QgsFieldProxyModel::Filters filters)
setFilters allows fitering according to the type of field

Signals

void fieldChanged(const QString& fieldName)
the signal is emitted when the currently selected field changes

Public slots

void setField(const QString& fieldName)
setField sets the currently selected field
void setLayer(QgsMapLayer* layer)
Sets the layer for which fields are listed in the combobox.

Function documentation

QgsFieldComboBox::QgsFieldComboBox(QWidget* parent = nullptr) explicit

QgsFieldComboBox creates a combo box to display the fields of a layer.

The layer can be either manually given or dynamically set by connecting the signal QgsMapLayerComboBox::layerChanged to the slot setLayer.

bool QgsFieldComboBox::allowEmptyFieldName() const

Returns true if the combo box allows the empty field ("not set") choice.

QgsVectorLayer* QgsFieldComboBox::layer() const

Returns the layer currently associated with the combobox.

void QgsFieldComboBox::setAllowEmptyFieldName(bool allowEmpty)

Sets whether an optional empty field ("not set") option is shown in the combo box.

void QgsFieldComboBox::setLayer(QgsMapLayer* layer) public slot

Sets the layer for which fields are listed in the combobox.

If no layer is set or a non-vector layer is set then the combobox will be empty.