How to know user select item by mouse move?
-
Qt5.15+vs2019
QTableView + model
The step:
- MouseClicked in QModelIndex(0,0)
- move mouse
- MouseRelease in QModelIndex(0,3)
Now ,there are four items in the first column is actived(Maybe selected,i just know the background-color of these item is blue,and the other is white). So I want to know which items are selected.
The first ,i use SIGNAL actived(const QModelIndex),but the SLOT can't receive any index.
And then i try to inherit QTableView and reimplement MouseEvent,it looks like
void MyTableView::mouseReleased(QMouseEvent event){ //How to find all item that choosed by MouseMove? event->accept(); }Do you have any better idea?
-
Qt5.15+vs2019
QTableView + model
The step:
- MouseClicked in QModelIndex(0,0)
- move mouse
- MouseRelease in QModelIndex(0,3)
Now ,there are four items in the first column is actived(Maybe selected,i just know the background-color of these item is blue,and the other is white). So I want to know which items are selected.
The first ,i use SIGNAL actived(const QModelIndex),but the SLOT can't receive any index.
And then i try to inherit QTableView and reimplement MouseEvent,it looks like
void MyTableView::mouseReleased(QMouseEvent event){ //How to find all item that choosed by MouseMove? event->accept(); }Do you have any better idea?
@qazaq408
Before you go anywhere near mouse move/click, why aren't you using the item selection model, like void QTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) or (preferable) the signal void QItemSelectionModel::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) on the table view's QItemSelectionModel *QAbstractItemView::selectionModel() const? -
@qazaq408
You can use QItemSelectionModel to get selected items, just like thisQModelIndexList indexList = tableView->selectionModel()->selectedIndexes();https://doc.qt.io/qt-6/qitemselectionmodel.html#selectedIndexes
https://doc.qt.io/qt-6/qitemselectionmodel.html#selectedColumns
https://doc.qt.io/qt-6/qitemselectionmodel.html#selectedRows -
@qazaq408
Before you go anywhere near mouse move/click, why aren't you using the item selection model, like void QTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) or (preferable) the signal void QItemSelectionModel::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) on the table view's QItemSelectionModel *QAbstractItemView::selectionModel() const? -
Q qazaq408 has marked this topic as solved on