How to do custom Selection in QTableWidget?
-
QTableWidget consists of several Selection Modi, which are selectable with the method
setSelectionMode (QAbstractItemView::SelectionMode mode)
None of the given modi fits the type of interactive selection i want to have. I want to implement a selection mode where when a user clicks in one table cell, and then shift+clicks in another table cell, the resulting selection is not a sum of columns and rows between these two, but starts from the first clicked cell, goes in read direction along row by row, ending by the second click. This is how it is implemented for example in windows explorer when you are having the grid / tiled view. I hope i made clear what i want to do.
Do i need to overwrite the QItemSelectionModel or the QTableWidget? Where are the user clicks for selection are processed?
This Question is related to Qt 4.8 Desktop Edition, C++
-
Hi and welcome to the forum!
have a look at "this doc":http://qt-project.org/doc/qt-5.0/qtwidgets/model-view-programming.html#handling-selections-in-item-views
It's explained with examples how to deal with this.
-
So following the instruction i need to write my own QItemSelectionModel.
But there is a problem with it.QTableWidget->setSelectionModel does only accept QItemSelectionModel based class. But when i want to inherit from that, i need a QAbstractItemModel for its constructor, where do i get that from?
Alternatively the instructions want me to use QAbstractTableModel. But also i can inherit from it with no problems, this is not accepted from the above given method. What to do now? -
Hi,
You give it the model it must act on, in this case the QTableWidget's model