Tracking Drag & Drop mouse cursor position?
I am trying to expand an existing drag & drop implementation. When dragging a row element from one QTableWidget to another, I need to be able to identify the type of object the row under the mouse cursor represents to determine if a drop is allowed.
For example, I am dragging a row representing an object of type X. The drop table contains objects of type X, Y and Z. When the drag cursor is above objects NOT of type X the cursor should change and a drop not allowed.
Using dragEnterEvent() and dragMoveEvent() I can tell what the row type is when the cursor enters the QTableWidget but not when it moves to another row in the same table. How can I track the position of the curson during a drag operation?
Re: Tracking Drag & Drop mouse cursor position?
Quote:
Originally Posted by mclark
Using dragEnterEvent() and dragMoveEvent() I can tell what the row type is when the cursor enters the QTableWidget but not when it moves to another row in the same table. How can I track the position of the curson during a drag operation?
dragMoveEvent does allow what you seek. Use the indexAt() method to get the item index. It contains both the row and column number of the hovered item.
Re: Tracking Drag & Drop mouse cursor position?
Quote:
dragMoveEvent does allow what you seek. Use the indexAt() method to get the item index.
I cannot find an available function called indexAt() for QDragMoveEvent, although pos() will give me the mouse coordinates as a QPoint object.
Re: Tracking Drag & Drop mouse cursor position?
I found what you were referring to. Many thanks for your help.
Re: Tracking Drag & Drop mouse cursor position?
The cursor changes to Qt::ForbiddenCursor when the mouse cursor crosses the row or column header of another QTableWidget. I does not change back while in that table. If entering the table from the right or bottom, a drop can be completed because the cursor is the regular drag cursor but not when the Qt::ForbiddenCursor is showing.
How can the cursor be changed back once the mouse has finished passing over the row or column header?
Re: Tracking Drag & Drop mouse cursor position?
Did you reimplement dragEnterEvent? Can you show me the code you wrote concerning dragging?
Re: Tracking Drag & Drop mouse cursor position?
These are the implementations of dragEnterEvent() and dragMoveEvent() I'm working with:
Code:
{
if ( pEvent->mimeData()->hasFormat( MY_MIME_TYPE ) )
{
if ( pEvent->source() == this ) // same table, move entry
{
pevent->setDropAction( Qt::MoveAction );
pevent->accept();
}
else // different table, add entry
{
if ( pItem != 0 )
{
int nDropRow = row( pItem );
if ( nDropRow != -1 )
{
QString sType
= item
( nDropRow, COL_DeviceType
)->text
();
if ( sType.compare( m_parent->m_sDragDeviceType ) != 0 )
pEvent->ignore();
}
}
else
pEvent->acceptProposedAction();
}
}
else
pEvent->ignore();
}
{
if ( pEvent->mimeData()->hasFormat( MY_MIME_TYPE ) )
pEvent->acceptProposedAction();
}
Re: Tracking Drag & Drop mouse cursor position?
Solved this one. Some debugging code was biting me in the backside :o! Thanks for the help wysota!