Class: QgsFieldComboBox

class qgis.gui.QgsFieldComboBox

Bases: PyQt5.QtWidgets.QComboBox

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.

QgsFieldComboBox(parent: QWidget = None) 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.

Methods

actionEvent

allowEmptyFieldName

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

changeEvent

childEvent

closeEvent

connectNotify

contextMenuEvent

create

currentField

Returns the currently selected field

customEvent

destroy

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

dropEvent

enterEvent

fields

Returns the fields currently shown in the combobox.

filters

currently used filter on list of fields

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

hideEvent

indexChanged

param i:

initPainter

initStyleOption

inputMethodEvent

isSignalConnected

keyPressEvent

keyReleaseEvent

layer

Returns the layer currently associated with the combobox.

leaveEvent

metric

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveEvent

nativeEvent

paintEvent

receivers

resizeEvent

sender

senderSignalIndex

setAllowEmptyFieldName

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

setField

setField sets the currently selected field

setFields

Manually sets the fields to use for the combo box.

setFilters

setFilters allows filtering according to the type of field

setLayer

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

sharedPainter

showEvent

tabletEvent

timerEvent

updateMicroFocus

wheelEvent

Signals

fieldChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

actionEvent(self, QActionEvent)
allowEmptyFieldName(self) bool

Returns True if the combo box allows the empty field (“not set”) choice.

Return type:

bool

changeEvent(self, QEvent)
childEvent(self, QChildEvent)
closeEvent(self, QCloseEvent)
connectNotify(self, QMetaMethod)
contextMenuEvent(self, QContextMenuEvent)
create(self, window: PyQt5.sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
currentField(self) str

Returns the currently selected field

Return type:

str

customEvent(self, QEvent)
destroy(self, destroyWindow: bool = True, destroySubWindows: bool = True)
disconnectNotify(self, QMetaMethod)
dragEnterEvent(self, QDragEnterEvent)
dragLeaveEvent(self, QDragLeaveEvent)
dragMoveEvent(self, QDragMoveEvent)
dropEvent(self, QDropEvent)
enterEvent(self, QEvent)
fieldChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...) –

  • revision (int = ...) –

  • arguments (Sequence = ...) –

Return type:

PYQT_SIGNAL

fields(self) QgsFields

Returns the fields currently shown in the combobox.

This will either be fields from the associated layer() or the fields manually set by a call to setFields().

New in version 3.14.

Return type:

QgsFields

filters(self) QgsFieldProxyModel.Filters

currently used filter on list of fields

Return type:

QgsFieldProxyModel.Filters

focusInEvent(self, QFocusEvent)
focusNextChild(self) bool
focusNextPrevChild(self, bool) bool
focusOutEvent(self, QFocusEvent)
focusPreviousChild(self) bool
hideEvent(self, QHideEvent)
indexChanged(self, i: int)
Parameters:

i (int) –

initPainter(self, QPainter)
initStyleOption(self, QStyleOptionComboBox)
inputMethodEvent(self, QInputMethodEvent)
isSignalConnected(self, QMetaMethod) bool
keyPressEvent(self, QKeyEvent)
keyReleaseEvent(self, QKeyEvent)
layer(self) QgsVectorLayer

Returns the layer currently associated with the combobox.

See also

setLayer()

Return type:

QgsVectorLayer

leaveEvent(self, QEvent)
metric(self, QPaintDevice.PaintDeviceMetric) int
mouseDoubleClickEvent(self, QMouseEvent)
mouseMoveEvent(self, QMouseEvent)
mousePressEvent(self, QMouseEvent)
mouseReleaseEvent(self, QMouseEvent)
moveEvent(self, QMoveEvent)
nativeEvent(self, Union[QByteArray, bytes, bytearray], PyQt5.sip.voidptr) Tuple[bool, int]
paintEvent(self, QPaintEvent)
receivers(self, PYQT_SIGNAL) int
resizeEvent(self, QResizeEvent)
sender(self) QObject
senderSignalIndex(self) int
setAllowEmptyFieldName(self, allowEmpty: bool)

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

Parameters:

allowEmpty (bool) –

setField(self, fieldName: str)

setField sets the currently selected field

Parameters:

fieldName (str) –

setFields(self, fields: QgsFields)

Manually sets the fields to use for the combo box.

This method should only be used when the combo box ISN’T associated with a layer() and needs to show the fields from an arbitrary field collection instead. Calling setFields() will automatically clear any existing layer().

See also

fields()

New in version 3.14.

Parameters:

fields (QgsFields) –

setFilters(self, filters: QgsFieldProxyModel.Filters | QgsFieldProxyModel.Filter)

setFilters allows filtering according to the type of field

Parameters:

filters (Union[QgsFieldProxyModel.Filters) –

setLayer(self, layer: QgsMapLayer)

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.

See also

layer()

Parameters:

layer (QgsMapLayer) –

sharedPainter(self) QPainter
showEvent(self, QShowEvent)
tabletEvent(self, QTabletEvent)
timerEvent(self, QTimerEvent)
updateMicroFocus(self)
wheelEvent(self, QWheelEvent)