Class: QgsQueryResultWidget

class qgis.gui.QgsQueryResultWidget

Bases: PyQt5.QtWidgets.QWidget

The QgsQueryResultWidget class allows users to enter and run an SQL query on a DB connection (an instance of QgsAbstractDatabaseProviderConnection).

Query results are displayed in a table view. Query execution and result fetching can be interrupted by pressing the “Stop” push button.

The widget supports a few QueryWidgetMode modes that pre-configure the widget appearance to be used in different contexts like when updating the SQL of an existing query layer.

Note

the ownership of the connection is transferred to the widget.

New in version 3.22.

QgsQueryResultWidget(parent: QWidget = None, connection: QgsAbstractDatabaseProviderConnection = None) Creates a QgsQueryResultWidget with the given connection, ownership is transferred to the widget.

Enums

QueryWidgetMode

Bases: enum.IntEnum

Methods

actionEvent

changeEvent

childEvent

closeEvent

connectNotify

contextMenuEvent

create

customEvent

destroy

disconnectNotify

dragEnterEvent

dragLeaveEvent

dragMoveEvent

dropEvent

enterEvent

event

executeQuery

Starts executing the query.

focusInEvent

focusNextChild

focusNextPrevChild

focusOutEvent

focusPreviousChild

hideEvent

initPainter

inputMethodEvent

isSignalConnected

keyPressEvent

keyReleaseEvent

leaveEvent

metric

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveEvent

nativeEvent

notify

Displays a message with text title and level in the widget's message bar.

paintEvent

receivers

resizeEvent

sender

senderSignalIndex

setConnection

Sets the connection to connection, ownership is transferred to the widget.

setQuery

Convenience method to set the SQL editor text to sql.

setSqlVectorLayerOptions

Initializes the widget from options.

setWidgetMode

Sets the widget mode to widgetMode, default is SqlQueryMode.

sharedPainter

showError

Hides the result table and shows the error title and message in the message bar or in the SQL error panel is isSqlError is set.

showEvent

tabletEvent

timerEvent

tokensReady

Triggered when the threaded API fetcher has new tokens to add.

updateMicroFocus

wheelEvent

Signals

createSqlVectorLayer

Emitted when a new vector SQL (query) layer must be created.

firstResultBatchFetched

Emitted when the first batch of results has been fetched.

class QueryWidgetMode(value)

Bases: enum.IntEnum

The QueryWidgetMode enum represents various modes for the widget appearance.

  • SqlQueryMode: Defaults widget mode for SQL execution and SQL query layer creation.

  • QueryLayerUpdateMode: SQL query layer update mode: the create SQL layer button is renamed to ‘Update’ and the SQL layer creation group box is expanded.

QueryLayerUpdateMode = 2
SqlQueryMode = 1
baseClass

alias of qgis._gui.QgsQueryResultWidget

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

Emitted when a new vector SQL (query) layer must be created.

Parameters
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
executeQuery(self)

Starts executing the query.

firstResultBatchFetched

Emitted when the first batch of results has been fetched.

Note

If the query returns no results this signal is not emitted. [signal]

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)
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]
notify(self, title: str, text: str, level: Qgis.MessageLevel = Qgis.MessageLevel.Info)

Displays a message with text title and level in the widget’s message bar.

Parameters
  • title (str) –

  • text (str) –

  • level (Qgis.MessageLevel = Qgis.MessageLevel.Info) –

paintEvent(self, QPaintEvent)
receivers(self, PYQT_SIGNAL) int
resizeEvent(self, QResizeEvent)
sender(self) QObject
senderSignalIndex(self) int
setConnection(self, connection: QgsAbstractDatabaseProviderConnection)

Sets the connection to connection, ownership is transferred to the widget.

Parameters

connection (QgsAbstractDatabaseProviderConnection) –

setQuery(self, sql: str)

Convenience method to set the SQL editor text to sql.

Parameters

sql (str) –

setSqlVectorLayerOptions(self, options: QgsAbstractDatabaseProviderConnection.SqlVectorLayerOptions)

Initializes the widget from options.

Parameters

options (QgsAbstractDatabaseProviderConnection.SqlVectorLayerOptions) –

setWidgetMode(self, widgetMode: QgsQueryResultWidget.QueryWidgetMode)

Sets the widget mode to widgetMode, default is SqlQueryMode.

Parameters

widgetMode (QgsQueryResultWidget.QueryWidgetMode) –

sharedPainter(self) QPainter
showError(self, title: str, message: str, isSqlError: bool = False)

Hides the result table and shows the error title and message in the message bar or in the SQL error panel is isSqlError is set.

Parameters
  • title (str) –

  • message (str) –

  • isSqlError (bool = False) –

showEvent(self, QShowEvent)
tabletEvent(self, QTabletEvent)
timerEvent(self, QTimerEvent)
tokensReady(self, tokens: Iterable[str])

Triggered when the threaded API fetcher has new tokens to add.

Parameters

tokens (Iterable[str]) –

updateMicroFocus(self)
wheelEvent(self, QWheelEvent)