Hi,
Yes, following that example, I had removed the events from my view. Still not being called, got to be something simple?!
This is the code I have in my treewidget ( items in here I want to be draggable ) :
void DASignalTree
::mousePressEvent ( QMouseEvent * event
) {
if( event->button() == Qt::LeftButton )
{
m_startPos = event->pos();
}
}
void DASignalTree
::mouseMoveEvent( QMouseEvent * event
) {
if( event->buttons() & Qt::LeftButton )
{
int distance = ( event->pos() - m_startPos).manhattanLength();
{
if ( item )
{
startDrag();
}
}
}
// QTreeWidget::mouseMoveEvent( event );
}
void DASignalTree::startDrag()
{
DAMimeData* pMimeData = new DAMimeData;
pMimeData->setText( dragItem->text( 0 ) );
pDrag->setMimeData( pMimeData );
pDrag
->setPixmap
( QPixmap("images/new.png") );
theApp->AddText( dragItem->text( 0 ) );
if( pDrag->start(Qt::MoveAction) == Qt::MoveAction)
delete dragItem;
}
void DASignalTree::mousePressEvent ( QMouseEvent * event )
{
if( event->button() == Qt::LeftButton )
{
m_startPos = event->pos();
}
QTreeWidget::mousePressEvent( event );
}
void DASignalTree::mouseMoveEvent( QMouseEvent * event )
{
if( event->buttons() & Qt::LeftButton )
{
int distance = ( event->pos() - m_startPos).manhattanLength();
if( distance >= QApplication::startDragDistance() )
{
QTreeWidgetItem *item = itemAt( m_startPos );
if ( item )
{
startDrag();
}
}
}
// QTreeWidget::mouseMoveEvent( event );
}
void DASignalTree::startDrag()
{
QTreeWidgetItem* dragItem = currentItem();
DAMimeData* pMimeData = new DAMimeData;
pMimeData->setText( dragItem->text( 0 ) );
QDrag* pDrag = new QDrag( this );
pDrag->setMimeData( pMimeData );
pDrag->setPixmap( QPixmap("images/new.png") );
theApp->AddText( dragItem->text( 0 ) );
if( pDrag->start(Qt::MoveAction) == Qt::MoveAction)
delete dragItem;
}
To copy to clipboard, switch view to plain text mode
and the code in my model :
bool DACanTreeModel
::dropMimeData ( const QMimeData * data, Qt
::DropAction action,
int row,
int column,
const QModelIndex & parent
) {
return true;
}
{
}
QMimeData * DACanTreeModel
::mimeData ( const QModelIndexList
& indexes
) const {
}
Qt::DropActions DACanTreeModel::supportedDropActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}
Qt
::ItemFlags DACanTreeModel
::flags(const QModelIndex &index
) const{
if (index.isValid())
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
else
return Qt::ItemIsDropEnabled | defaultFlags;
}
bool DACanTreeModel::dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent )
{
return true;
}
QStringList DACanTreeModel::mimeTypes () const
{
return QStringList();
}
QMimeData * DACanTreeModel::mimeData ( const QModelIndexList & indexes ) const
{
return new QMimeData();
}
Qt::DropActions DACanTreeModel::supportedDropActions() const
{
return Qt::CopyAction | Qt::MoveAction;
}
Qt::ItemFlags DACanTreeModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags defaultFlags = QAbstractTableModel::flags(index);
if (index.isValid())
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
else
return Qt::ItemIsDropEnabled | defaultFlags;
}
To copy to clipboard, switch view to plain text mode
And finally the view constructor :
DATableView
::DATableView(QWidget *parent
){
setAcceptDrops(true);
setDropIndicatorShown(true);
}
DATableView::DATableView(QWidget *parent)
: QTableView(parent)
{
setAcceptDrops(true);
setDropIndicatorShown(true);
}
To copy to clipboard, switch view to plain text mode
I'm at a loss?!
Regards,
Steve
Bookmarks