Results 1 to 3 of 3

Thread: Realtime TableView filter with (lineEdit)

  1. #1
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Realtime TableView filter with (lineEdit)

    Hi,

    I want to know how to do a hide/show filter on a QTableView. In the same way as the KDE applications.

    I've tried this code but it's too slow:

    Qt Code:
    1. void MainWindow::on_lineEdit_textChanged(const QString &text){
    2. FilterThread thread(text, queryModel, tableView);
    3.  
    4. thread.run();
    5. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. FilterThread::FilterThread(QString text, QueryModel *model, QTableView *table, QObject *parent):QThread(parent){
    2. m_text=text;
    3. m_model=model;
    4. m_table=table;
    5. }
    6. void FilterThread::run(){
    7. for(int i=0;i<m_model->rowCount();i++){
    8. QString title=m_model->data(m_model->index(i, 3)).toString();
    9.  
    10. m_table->setRowHidden(i, title.indexOf(m_text, 0, Qt::CaseInsensitive)==-1);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    Thank's

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Realtime TableView filter with (lineEdit)

    Don't modify widgets from any other thread than the main GUI thread:
    Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread.
    Try QSortFilterProxyModel, or if that's a QSqlQueryModel, maybe you could do the filtering on the database side?
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    xgoan (21st December 2006)

  4. #3
    Join Date
    Jul 2006
    Posts
    126
    Thanks
    17
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Realtime TableView filter with (lineEdit)

    Quote Originally Posted by jpn View Post
    Don't modify widgets from any other thread than the main GUI thread:


    Try QSortFilterProxyModel, or if that's a QSqlQueryModel, maybe you could do the filtering on the database side?
    The Thread was a try to speed up the action.

    The problem of try the db side is that I only want to hide the rows, not remove it. And yes it's a QSqlQueryModel derived class. (QODBC MSAccess conection)

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.