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

copyResults

Copies the query results to the clipboard, as a formatted table.

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

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

firstResultBatchFetched

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

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 QgsQueryResultWidget

actionEvent(self, QActionEvent)
changeEvent(self, QEvent)
childEvent(self, QChildEvent)
closeEvent(self, QCloseEvent)
connectNotify(self, QMetaMethod)
contextMenuEvent(self, QContextMenuEvent)
copyResults(self)

Copies the query results to the clipboard, as a formatted table.

New in version 3.32.

copyResults(self, fromRow: int, toRow: int, fromColumn: int, toColumn: int) Copies a range of the query results to the clipboard, as a formatted table.

New in version 3.32.

create(self, window: PyQt5.sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True)
createSqlVectorLayer

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

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

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

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], PyQt5.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)