QTableView Sample ( Search and Filter ) !

2,699 views
Skip to first unread message
Assigned to ron...@gmail.com by me

M., Ronaldo

unread,
Sep 21, 2013, 12:58:13 PM9/21/13
to qtcon...@googlegroups.com
HI all !


Can I have a generic example for a QTableView that search a string, then show only line(s) matched ?


oTView := QTableView()
// populate it with strings: dtos( date() ) ... dtos( date()+1000 )
...

oString := QString()
// settext( dtos( date()+500 )
...

// Now search and filter
oTView: ???



Regards

M., Ronaldo

unread,
Sep 21, 2013, 6:30:49 PM9/21/13
to qtcon...@googlegroups.com
To search on all data from QTableView, I can use:

qList := ::QTableView:findItems( oString.Text(), Qt_MatchContains )

But how to search only in a specific Collumn ?


Regards

Francesco Perillo

unread,
Sep 21, 2013, 6:40:22 PM9/21/13
to qtcontribs
You should give a bit more info I think.

I may only say that I use a QTableWidget and load 50000+ rows in about 3 seconds. I have a QLineEdit and a timer that fires every 0,5 seconds. In the timer routine I check if the QLineEdit content is changed and if it is, I "zap" the QTableWidget and load al the data back... it's quicker since the dbf is small and local.

Probably it's not the best solution but it works for me. Quick and dirty and able to handle my needs and dbfs.

What is best for you can only be determined when you tell us about the data source: local/lan, number of rows, number of columns, kind of cells, if you keep a copy of your data in a model... if you have just 1000 records I think my solution is ok...



--
You received this message because you are subscribed to the Google Groups "QtContribs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qtcontribs+...@googlegroups.com.
To post to this group, send email to qtcon...@googlegroups.com.
Visit this group at http://groups.google.com/group/qtcontribs.
For more options, visit https://groups.google.com/groups/opt_out.

M., Ronaldo

unread,
Sep 21, 2013, 7:00:00 PM9/21/13
to qtcon...@googlegroups.com
Hi Francesco !


The abstract data will be ever from a multdimensional array()

Then like You said: I can zap the QTableView and repopulate it with data match only.


Thanks for reply :)



DBF: In a network we can copy all data table to an array and use the same concept ( indirect access )

I think for sqLite we can use QSqlTableModel, it's correct ?



Regards

Francesco Perillo

unread,
Sep 21, 2013, 7:04:52 PM9/21/13
to qtcontribs
The abstract data will be ever from a multdimensional array()

Then like You said: I can zap the QTableView and repopulate it with data match only.

I repeat: this is the quickest way... I didn't check how this can be achieved using Qt methods... probably you can do creating a QModel and I know it can be fitlered and sorted... but you add layer of complexity...
 
DBF: In a network we can copy all data table to an array and use the same concept ( indirect access )

Yes, if you are ok that data on the server may be changed by some other user...
 

I think for sqLite we can use QSqlTableModel, it's correct ?

Yes, I think you can use it but I can't say for sure since I never used it.

Ciao,
Francesco

M., Ronaldo

unread,
Nov 9, 2017, 7:01:35 PM11/9/17
to QtContribs
QTableView Sample: Using a QSqlTableModel

QTableView.zip
Auto Generated Inline Image 1
Reply all
Reply to author
Forward
0 new messages