Results 1 to 3 of 3

Thread: [SOLVED]How to reset a model filter ?

  1. #1
    Join Date
    Sep 2015
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default [SOLVED]How to reset a model filter ?

    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.
    Qt Code:
    1. import sys
    2. from ui import * # My ui.py file
    3. from PyQt4 import QtSql, QtGui
    4.  
    5. class MyForm(QtGui.QDialog):
    6. def __init__(self, parent=None):
    7. QtGui.QWidget.__init__(self, parent)
    8. self.ui = Ui_Dialog()
    9. self.ui.setupUi(self)
    10. self.model = QtSql.QSqlTableModel(self)
    11. self.query = QtSql.QSqlQueryModel(self)
    12. self.model.setTable("produtos")
    13. self.model.setEditStrategy(QtSql.QSqlTableModel.OnManualSubmit)
    14. self.model.select()
    15. self.ui.tableView.setModel(self.model)
    16. QtCore.QObject.connect(self.ui.FilterButton, QtCore.SIGNAL('clicked()'), self.FilterRecords)
    17.  
    18. def FilterRecords(self):
    19. text = self.ui.prodname.text()
    20. if len(text) == 0:
    21. ... here i want to make setFilter(void) to just redisplay all table ... (1)
    22. How could i do that ?
    23. else:
    24. self.model.setFilter("name = '%s'" % text)
    To copy to clipboard, switch view to plain text mode 

    First port here, sorry if is a noob question. I searched on the docs, but cant find a solution.
    Last edited by chiruL; 10th September 2015 at 22:00. Reason: solved

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,323
    Thanks
    36
    Thanked 1,526 Times in 1,477 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to reset a model filter ?

    what about just
    Qt Code:
    1. self.model.setFilter("");
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Sep 2015
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to reset a model filter ?

    worked, thanks !!

Similar Threads

  1. How to reset model without collapsing tree?
    By neuronet in forum Newbie
    Replies: 13
    Last Post: 22nd February 2015, 17:34
  2. QTreeView expansion after model reset
    By d_stranz in forum Qt Programming
    Replies: 3
    Last Post: 3rd December 2014, 23:42
  3. Replies: 5
    Last Post: 10th March 2011, 20:06
  4. Model/view, apply a filter on model
    By remy_david in forum Qt Programming
    Replies: 4
    Last Post: 4th February 2011, 17:13
  5. Replies: 3
    Last Post: 31st March 2008, 21:23

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.