QTableWidget - get column/row from under mouse ?
-
-
Hi,
Can you show the current code you are using ?
-
Actually I found out that I need cellEntered signal, but that does not happen as I'm dragging data in to the view, I just want to know whats under my mouse and if I need to make new cell/new data widget in cell or drop in to existing data widget in cell.
Not much code yet... except for basic QDropEvent()/dragEnterEvent/dragMoveEvent events...
-
The events you get as parameter gives you the position of the cursor. So you can check what's under it more precisely.
-
Hi
You can use
https://doc.qt.io/qt-5/qtablewidget.html#itemAt-1
to get item under the cursor.
You can then ask Item for Col/row if u need that. -
@mrjj said in QTableWidget - get column/row from under mouse ?:
Hi
You can use
https://doc.qt.io/qt-5/qtablewidget.html#itemAt-1
to get item under the cursor.
You can then ask Item for Col/row if u need that.This return null if there is no item in column.
@SGaist said in QTableWidget - get column/row from under mouse ?:
The events you get as parameter gives you the position of the cursor. So you can check what's under it more precisely.
I get no event when I'm dragging in a data from other widget/view/source.
-
Can you show your current implementation ?
-
filterDropIndator() is where I try to figure out the position of the mouse...
void TableWidget::dragEnterEvent(QDragEnterEvent *event) { if (event->source() == this) { qDebug() << "Internal"; setDragDropMode(QAbstractItemView::InternalMove); } else { qDebug() << "External"; setDragDropMode(QAbstractItemView::DropOnly); } if (event->mimeData()->hasFormat("templateItemDrag")) { qDebug() << "111" << event << "\n3213213" << event->proposedAction() << event->possibleActions() << event->dropAction(); event->acceptProposedAction(); } //QAbstractItemView::dragEnterEvent(event); } void TableWidget::dragMoveEvent(QDragMoveEvent *event) { event->accept(); filterDropIndator(event); //QAbstractItemView::dragMoveEvent(event); } void TableWidget::dragLeaveEvent(QDragLeaveEvent *event) { QAbstractItemView::dragLeaveEvent(event); } void TableWidget::dropEvent(QDropEvent *event) { qDebug() << "yay ?v3whyg345hg3w"; if (event->mimeData()->hasFormat("templateItemDrag")) { qDebug() << "2132145215215"; event->acceptProposedAction(); return; } QTableWidget::dropEvent(event); } TableWidget::TableWidget(QWidget *parentPtr) : QTableWidget(parentPtr) { setAcceptDrops(true); setDragEnabled(true); //viewport()->setAcceptDrops(true); //setDragDropOverwriteMode(false); setDropIndatorShown(true); setDefaultDropAction(Qt::MoveAction); setColumnCount(10); setRowCount(1); connect(this, &QTableWidget::cellEntered, this, &TableWidget::newMousePos); } TableWidget::~TableWidget() { } void TableWidget::filterDropIndator(QDragMoveEvent *event) { auto *w = itemAt(event->pos()); if (w) { } else { qDebug() << "Row pos/col = " << mRow << mColumn; } qDebug() << "filtering indator :" << w; } void TableWidget::newMousePos(int row, int column) { mRow = row; mColumn = column; }