PDA

View Full Version : [SOLVED]How to reset a model filter ?



chiruL
10th September 2015, 21:04
HI, i am trying to make a simple Pyqt application which will be a data base manager. Im using the QSqlTableModel as model, but im having trouble to do simples tasks.


import sys
from ui import * # My ui.py file
from PyQt4 import QtSql, QtGui

class MyForm(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.model = QtSql.QSqlTableModel(self)
self.query = QtSql.QSqlQueryModel(self)
self.model.setTable("produtos")
self.model.setEditStrategy(QtSql.QSqlTableModel.On ManualSubmit)
self.model.select()
self.ui.tableView.setModel(self.model)
QtCore.QObject.connect(self.ui.FilterButton, QtCore.SIGNAL('clicked()'), self.FilterRecords)

def FilterRecords(self):
text = self.ui.prodname.text()
if len(text) == 0:
... here i want to make setFilter(void) to just redisplay all table ... (1)
How could i do that ?
else:
self.model.setFilter("name = '%s'" % text)


First port here, sorry if is a noob question. I searched on the docs, but cant find a solution.

anda_skoa
10th September 2015, 21:49
what about just


self.model.setFilter("");


Cheers,
_

chiruL
10th September 2015, 22:02
worked, thanks !!