Selecting a row from a table
-
I have a QTableView, and I use a QSortFilterProxyModel beetwen the model and the view.
In the line:
@ void MyWidget::mousePressEvent(QMouseEvent* event) @
I'd like to select a row (I have 10 rows in the table) from the tableview:@
QTableView temp = static_cast<QTableView>(this);
QSortFilterProxyModel proxy = static_cast<QSortFilterProxyModel>(temp->model());
QItemSelectionModel *selectionModel = temp->selectionModel();QModelIndexList indexes = selectionModel->selectedRows();
@But my indexes has always 0 item. Why? What is wrong?
-
I think mousePressEvent function is not what you really, because the function is probably called before the selection of the items. And be careful that this function will be called if you click any where on the widget, not just the row.
You should connect a slot to the activate/clicked/pressed signal from the QTableView widget.
-
[quote author="SaiyanRiku" date="1355136345"]I think mousePressEvent function is not what you really, because the function is probably called before the selection of the items. And be careful that this function will be called if you click any where on the widget, not just the row.
You should connect a slot to the activate/clicked/pressed signal from the QTableView widget.[/quote]
I (probably) need the mousePressEvent, because I'd like to drag (Drag and Drop) a line from my table. I have to make here a mimedata.
How can I solve this anyway?
-
I never use the drag and drop, but i think if you can't deal with activate/clicked/pressed signal you can try to get the index where the pointer is with the QTableView::indexAt and the mouse event position and merge it with selectedRows.