PDA

View Full Version : [QTableView] Custom selection behaviour



Rid
18th April 2011, 13:05
Hi,

I'm new on this forum, so here is a short introduction.
My alias is Rid, I'm French, and I'm praticing Qt since January 2010.

I have a question concerning the way items are selected within a QTableView and the way we can modify it.
Indeed, if I select an item, hold Shift-Key and then select*another item, this is what I get:
http://img855.imageshack.us/img855/6528/image1p.png

I would like to modify this behaviour in order to select every items between the selected ones as in
this screenshot:
http://img708.imageshack.us/img708/5286/image2azo.png

I've made some tests in which I modified QTableView's select mode and behaviour, but they failed.
Can somebody give me help on this problem?

Lykurg
18th April 2011, 13:50
Salut!

What's about C1 and D1? And please attach the images at this forum and don't use 3rd party sites. I don't know a "build in" function for that, but you could react on the signals of the selection model and make your own selection behavior. Or more sophisticated: make your own QItemSelectionModel and set it to your table view via QTableView::setSelectionModel().

Rid
18th April 2011, 18:29
Thanks for your answer Lykburg.

As I was unable to code what I wanted, I've used OpenOffice to make my screenshots, and I forgot to select C1..
I think I will try to make my own QItemSelectionModel. I will update this thread...

Rajesh.Rathod
27th April 2012, 08:17
You derive new class from QTableView and handle mouse press and release event. In mouse press event store start cell index and on mouse release store end cell index and then in mouse release handler, you can clear current selection and write algorithm which makes list of cells which needs to be selected based on start cell index and end cell index and add list in selection model of the table.

This is the way of custom handling of QTableView selection, I hope this is clear.