Class: QgsQueryBuilder

class qgis.gui.QgsQueryBuilder

Bases: QgsSubsetStringEditorInterface

Query Builder for layers.

The query builder allows interactive creation of a SQL for limiting the features displayed in a vector layer. The fields in the table are displayed and sample values (or all values) can be viewed to aid in constructing the query. A test function returns the number of features that will be returned.

QgsQueryBuilder(layer: QgsVectorLayer, parent: QWidget = None, fl: Union[Qt.WindowFlags, Qt.WindowType] = QgsGuiUtils.ModalDialogFlags) This constructor is used when the query builder is called from the vector layer properties dialog

actionEvent(self, QActionEvent)
changeEvent(self, QEvent)
childEvent(self, QChildEvent)
closeEvent(self, QCloseEvent)
codeEditorWidget(self) QgsCodeEditor

Returns the code editor widget for the SQL.

New in version 3.18.

Return type


connectNotify(self, QMetaMethod)
contextMenuEvent(self, QContextMenuEvent)
create(self, window: sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
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)
event(self, QEvent) bool
eventFilter(self, QObject, QEvent) bool
focusInEvent(self, QFocusEvent)
focusNextChild(self) bool
focusNextPrevChild(self, bool) bool
focusOutEvent(self, QFocusEvent)
focusPreviousChild(self) bool
hideEvent(self, QHideEvent)
initPainter(self, QPainter)
inputMethodEvent(self, QInputMethodEvent)
isSignalConnected(self, QMetaMethod) bool
keyPressEvent(self, QKeyEvent)
keyReleaseEvent(self, QKeyEvent)
leaveEvent(self, QEvent)

Load query from the XML file

New in version 3.16.

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], sip.voidptr) Tuple[bool, int]
paintEvent(self, QPaintEvent)
receivers(self, PYQT_SIGNAL) int
resizeEvent(self, QResizeEvent)

Save query to the XML file

New in version 3.16.

sender(self) QObject
senderSignalIndex(self) int
setDatasourceDescription(self, uri: str)

uri (str) –

setSql(self, sqlStatement: str)

Set the sql statement to display in the dialog.


sqlStatement (str) –

setSubsetString(self, subsetString: str)

subsetString (str) –

sharedPainter(self) QPainter
showEvent(self, event: QShowEvent)

event (QShowEvent) –

sql(self) str

Returns the sql statement entered in the dialog.

Return type


subsetString(self) str
Return type


tabletEvent(self, QTabletEvent)

The default implementation tests that the constructed sql statement to see if the vector layer data provider likes it. The number of rows that would be returned is displayed in a message box. The test uses a “select count(*) from …” query to test the SQL statement.

timerEvent(self, QTimerEvent)
wheelEvent(self, QWheelEvent)