Eduardo Silva
Eduardo Silva

Reputation: 25

QSqlTableModel with WHERE condition

How can i show a table with QTableView and WHERE condition ?

...WHERE numero_conta = 123;

        self.model = QSqlTableModel()
        self.model.setTable('historico')
        self.model.select()

        self.tab_extrato = QtWidgets.QTableView(self.tab_2)
        self.tab_extrato.setObjectName("tab_extrato")
        self.tab_extrato.setModel(self.model)
        self.tab_extrato.hideColumn(0)
        self.verticalLayout_9.addWidget(self.tab_extrato)

link. the entire code

enter image description here

Upvotes: 0

Views: 511

Answers (1)

eyllanesc
eyllanesc

Reputation: 244232

If you want to use "WHERE" then you want to filter the information so you must use the setFilter() method:

self.model = QSqlTableModel()
self.model.setTable('historico')
self.model.setFilter('numero_conta = 123')
self.model.select()

Upvotes: 2

Related Questions