Class: QgsExpressionTreeView

class qgis.gui.QgsExpressionTreeView(parent: QWidget = None)

Bases: PyQt5.QtWidgets.QTreeView

Constructor

QgsExpressionTreeView is a tree view to list all expressions functions, variables and fields that can be used in an expression.

New in version 3.14.

Parameters

parent

class MenuProvider

Bases: sip.wrapper

Constructor

QgsExpressionTreeView.MenuProvider(QgsExpressionTreeView.MenuProvider)

Implementation of this interface can be implemented to allow QgsExpressionTreeView instance to provide custom context menus (opened upon right-click).

New in version 3.14.

createContextMenu(self, item: QgsExpressionItem) → QMenu

Returns a newly created menu instance

Parameters

item (QgsExpressionItem) –

Return type

QMenu

actionEvent()
changeEvent()
childEvent()
closeEditor()
closeEvent()
columnCountChanged()
columnMoved()
columnResized()
commitData()
connectNotify()
contextMenuEvent()
create()
currentChanged()
currentExpressionItemChanged

Emitter when the current expression item changed [signal]

Parameters

item (QgsExpressionItem) –

currentItem(self)QgsExpressionItem

Returns the current item or a None

Return type

QgsExpressionItem

customEvent()
destroy()
dirtyRegionOffset()
disconnectNotify()
dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
drawBranches()
drawFrame()
drawRow()
drawTree()
dropEvent()
dropIndicatorPosition()
edit()
editorDestroyed()
enterEvent()
event()
eventFilter()
executeDelayedItemsLayout()
exportUserExpressions(self) → QJsonDocument

Create the expressions JSON document storing all the user expressions to be exported.

Return type

QJsonDocument

Returns

the created expressions JSON file

expressionContext(self)QgsExpressionContext

Returns the expression context for the widget. The context is used for the expression preview result and for populating the list of available functions and variables.

Return type

QgsExpressionContext

expressionItemDoubleClicked

Emitted when a expression item is double clicked [signal]

Parameters

text (str) –

findExpressions(self, label: str) → List[QgsExpressionItem]

Returns the list of expression items matching a label.

Parameters

label (str) –

Return type

List[QgsExpressionItem]

focusInEvent()
focusNextChild()
focusNextPrevChild()
focusOutEvent()
focusPreviousChild()
hideEvent()
horizontalOffset()
horizontalScrollbarAction()
horizontalScrollbarValueChanged()
indexRowSizeHint()
initPainter()
initStyleOption()
inputMethodEvent()
isIndexHidden()
isSignalConnected()
keyPressEvent()
keyReleaseEvent()
leaveEvent()
loadExpressionsFromJson(self, expressionsDocument: QJsonDocument)

Load and permanently store the expressions from the expressions JSON document.

Parameters

expressionsDocument (QJsonDocument) – the parsed expressions JSON file

loadFieldNames(self, fields: QgsFields)

This allows loading fields without specifying a layer

Parameters

fields (QgsFields) –

loadRecent(self, collection: str = '')

Loads the recent expressions from the given collection. By default it is loaded from the collection “generic”.

Parameters

collection (str = '') –

loadUserExpressions(self)

Loads the user expressions. This is done on request since it can be very slow if there are thousands of user expressions

metric()
mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent()
moveCursor()
moveEvent()
nativeEvent()
paintEvent()
project(self)QgsProject

Returns the project currently associated with the widget.

See also

setProject()

Return type

QgsProject

receivers()
reexpand()
refresh(self)

Refreshes the content of the tree

removeFromUserExpressions(self, label: str)

Removes the expression label from the user stored expressions.

Parameters

label (str) –

resizeEvent()
rowHeight()
rowsAboutToBeRemoved()
rowsInserted()
rowsRemoved()
saveToRecent(self, expressionText: str, collection: str = '')

Adds the current expression to the given collection. By default it is saved to the collection “generic”.

Parameters
  • expressionText (str) –

  • collection (str = '') –

saveToUserExpressions(self, label: str, expression: str, helpText: str)

Stores the user expression with given label and helpText.

Parameters
  • label (str) –

  • expression (str) –

  • helpText (str) –

scheduleDelayedItemsLayout()
scrollContentsBy()
scrollDirtyRegion()
selectedIndexes()
selectionChanged()
selectionCommand()
sender()
senderSignalIndex()
setDirtyRegion()
setExpressionContext(self, context: QgsExpressionContext)

Sets the expression context for the tree view. The context is used to populate the list of available functions and variables.

Parameters

context (QgsExpressionContext) – expression context

setLayer(self, layer: QgsVectorLayer)

Sets layer in order to get the fields and values

Parameters

layer (QgsVectorLayer) –

setMenuProvider(self, provider: QgsExpressionTreeView.MenuProvider)

Sets the menu provider. This does not take ownership of the provider

Parameters

provider (QgsExpressionTreeView.MenuProvider) –

setProject(self, project: QgsProject)

Sets the project currently associated with the widget. This controls which layers and relations and other project-specific items are shown in the widget.

See also

project()

Parameters

project (QgsProject) –

setSearchText(self, text: str)

Sets the text to filter the expression tree

Parameters

text (str) –

setSelection()
setState()
setViewportMargins()
sharedPainter()
showEvent()
sizeHintForColumn()
startDrag()
state()
tabletEvent()
timerEvent()
updateEditorData()
updateEditorGeometries()
updateGeometries()
updateMicroFocus()
verticalOffset()
verticalScrollbarAction()
verticalScrollbarValueChanged()
viewOptions()
viewportEvent()
viewportMargins()
viewportSizeHint()
visualRegionForSelection()
wheelEvent()