[solved] mousePressEvent on qtableview
-
I cannot get the mousePressEvent on my qtableview.
I'd like to select one row, but no one is selected.
(I'd like to drag one row and drop it into somewhere.)
How can I solve this? -
Do you call the base class QTableView::mousePressEvent() in your mousePressEvent()?
Or don't you get no event in the first place?
-
[quote author="Lukas Geyer" date="1357553560"]Do you call the base class QTableView::mousePressEvent() in your mousePressEvent()?
Or don't you get no event in the first place?[/quote]
More exactly:
Now I get mousePressEvent(), but no row is selected (highlighted)! I cannot get the row (cell) content. I need a cell content to my mime data for dragging.
(In the model I set correctly the flag that item is ItemIsSelectable.) -
If your overridden mousePressEvent() calls QTableView::mousePressEvent() it should behave exactly the same.
But what do you want to achieve in the first place?
If it is about enabling drag support with a custom MIME type just enable dragging, <code>QTableView::setDragDropMode(QAbstractItemView::DragOnly)</code> and either reimplement QAbstractItemModel::mimeData() in your model or override QAbstractItemView::startDrag() to provide your own QMimeData / QDrag object.
-
[quote author="Lukas Geyer" date="1357559553"]If your overridden mousePressEvent() calls QTableView::mousePressEvent() it should behave exactly the same.
But what do you want to achieve in the first place?
If it is about enabling drag support with a custom MIME type just enable dragging, <code>QTableView::setDragDropMode(QAbstractItemView::DragOnly)</code> and either reimplement QAbstractItemModel::mimeData() in your model or override QAbstractItemView::startDrag() to provide your own QMimeData / QDrag object.[/quote]
Yeaaaaaaaaah!
startDrag() was the solution!
Many thanks :) -
You're welcome.