Class: QgsDatabaseTableComboBox

The QgsDatabaseTableComboBox class is a combo box which displays the list of tables for a specific database connection.

Warning

The provider must support the connection API methods in its QgsProviderMetadata implementation in order for the combobox to work correctly.

Added in version 3.14.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsDatabaseTableComboBox

Base classes

QWidget

QObject

QPaintDevice

Methods

allowEmptyTable

Returns True if the combobox allows the empty table ("not set") choice.

comboBox

Returns the combobox portion of the widget.

currentSchema

Returns the schema of the current table selected in the combo box.

currentTable

Returns the name of the current table selected in the combo box.

refreshTables

Refreshes the list of available tables.

setAllowEmptyTable

Sets whether an optional empty table ("not set") option is present in the combobox.

setConnectionName

Sets the database connection name from which to retrieve the available tables.

setSchema

Sets the schema from which to retrieve the available tables.

setTable

Sets the current table selected in the combo box.

Signals

tableChanged

Emitted whenever the currently selected table changes.

class qgis.gui.QgsDatabaseTableComboBox[source]

Bases: QWidget

__init__(provider: str | None, connection: str | None, schema: str | None = '', parent: QWidget | None = None)

Constructor for QgsDatabaseTableComboBox, for the specified provider and connection.

The optional schema argument can be used to restrict the listed tables to a specific schema.

Warning

The provider must support the connection API methods in its QgsProviderMetadata implementation in order for the model to work correctly.

Parameters:
  • provider (Optional[str])

  • connection (Optional[str])

  • schema (Optional[str] = '')

  • parent (Optional[QWidget] = None)

__init__(connection: QgsAbstractDatabaseProviderConnection | None, schema: str | None = '', parent: QWidget | None = None)

Constructor for QgsDatabaseTableComboBox, for the specified connection.

The optional schema argument can be used to restrict the listed tables to a specific schema.

Ownership of connection is transferred to the combobox.

Parameters:
allowEmptyTable(self) bool[source]

Returns True if the combobox allows the empty table (“not set”) choice.

Return type:

bool

comboBox(self) QComboBox | None[source]

Returns the combobox portion of the widget.

Return type:

Optional[QComboBox]

currentSchema(self) str[source]

Returns the schema of the current table selected in the combo box.

Return type:

str

currentTable(self) str[source]

Returns the name of the current table selected in the combo box.

Return type:

str

refreshTables(self)[source]

Refreshes the list of available tables.

setAllowEmptyTable(self, allowEmpty: bool)[source]

Sets whether an optional empty table (“not set”) option is present in the combobox.

Parameters:

allowEmpty (bool)

setConnectionName(self, connection: str | None, provider: str | None = '')[source]

Sets the database connection name from which to retrieve the available tables.

Optionally the provider can be reset too.

Parameters:
  • connection (Optional[str])

  • provider (Optional[str] = '')

setSchema(self, schema: str | None)[source]

Sets the schema from which to retrieve the available tables.

Parameters:

schema (Optional[str])

setTable(self, table: str | None, schema: str | None = '')[source]

Sets the current table selected in the combo box.

If necessary, the schema can be specified too.

Parameters:
  • table (Optional[str])

  • schema (Optional[str] = '')

signal tableChanged(table: str, schema: str | None = None)[source]

Emitted whenever the currently selected table changes.

Parameters:
  • table (str)

  • schema (Optional[str] = None)