These are the implementations of dragEnterEvent() and dragMoveEvent() I'm working with:
{
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();
}
void MyTable::dragEnterEvent( QDragEnterEvent* pEvent )
{
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
{
QTableWidgetItem* pItem = itemAt( pEvent->pos() );
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();
}
void MyTable::dragMoveEvent( QDragMoveEvent* pEvent )
{
if ( pEvent->mimeData()->hasFormat( MY_MIME_TYPE ) )
pEvent->acceptProposedAction();
}
To copy to clipboard, switch view to plain text mode
Bookmarks