PDA

View Full Version : Drag And Drop Woooees



sticcino
3rd July 2008, 01:12
Hi,

I don't get it.... I have a QtableView in a dlg form, connected to a sql datasource recordset. the data displays fine, no problems. The problem is that i cannot drag a row from this view and drop it onto its parent window.

The table view is getting every signal except for dragMoveEvent

I've declared everything correctly, but still nothing. NOW.... if i change from QTableView to QTableWidget, dragging works!!, but i can then no longer use myView->setModel(mysqlset).

in .h


class QDragMoveEvent;
class QDragLeaveEvent;
class QDrag;
....

protected:
QDrag *getDragObject(QMouseEvent *event);

void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void dragMoveEvent(QDragMoveEvent * event);


in .cpp


// initialization
DlgLibraryEditor::DlgLibraryEditor(QWidget * parent, QSqlDatabase m_pPrimarydb) : QDialog(parent), Ui::DlgLibraryEditor()
{
setupUi(this);

//setup properties for table
m_pMusicTableView->setSelectionBehavior(QAbstractItemView::SelectRows );
m_pMusicTableView->setSelectionMode(QAbstractItemView::ExtendedSelect ion);
m_pMusicTableView->viewport()->setAcceptDrops(false);
m_pMusicTableView->viewport()->setAttribute(Qt::WA_StaticContents);

//Drag and drop setup
m_pMusicTableView->setDragEnabled(true);
m_pMusicTableView->setDragDropMode(QAbstractItemView::DragOnly);
m_pMusicTableView->setDropIndicatorShown(true);
m_pMusicTableView->setAcceptDrops(true);

...
}

void DlgLibraryEditor::dragEnterEvent(QDragEnterEvent * event)
{
event->ignore();
}

void DlgLibraryEditor::dragMoveEvent(QDragMoveEvent * event)
{
event->ignore();
}

void DlgLibraryEditor::dropEvent(QDropEvent * event)
{
event->ignore();
}


what gives ???

Thanks,
Johnny

Arghargh
3rd July 2008, 06:56
Hi, instead of ignoring the event, you could try to use


void DlgLibraryEditor::dragMoveEvent(QDragMoveEvent * event)
{
event->acceptProposedAction ();
}


Arghargh

wysota
3rd July 2008, 07:29
If you use the model based approach, then you should implement drag&drop in the model instead of messing with the view's events.

caduel
3rd July 2008, 07:33
other helpful stuff (sometimes)
* put a qDebug() << __PRETTY_FUNCTION__ inside those events, so you know they happen
* have you enabled drag / drop on the view (in designer, if you're using it)?
* QAbstractItemView (and subclasses) handle drag and drop; it is not necessary anymore for you to work on the level of these events. Instead read up on QAbstractItemModel::mimeData() etc.

HTH

sticcino
3rd July 2008, 17:07
* put a qDebug() << __PRETTY_FUNCTION__ inside those events, so you know they happen
>> yes, all dragNDrop Functions get hit except dragMoveEvent(QDragMoveEvent * event)

* have you enabled drag / drop on the view (in designer, if you're using it)?
>> yes, I am using designer, adn have enabled all drag options

* QAbstractItemView (and subclasses) handle drag and drop; it is not necessary anymore for you to work on the level of these events. Instead read up on QAbstractItemModel::mimeData() etc.

ok, but I can't understand why only dragMoveEvent(QDragMoveEvent * event) won't work. this is the same code that is located in 2 other places in the app,the difference being the other classes are based on QTableView and the dragmove event works???. Do these routines work differently when located in different view types??.


thanks
Johnny

jpn
5th July 2008, 23:23
ok, but I can't understand why only dragMoveEvent(QDragMoveEvent * event) won't work.
Because you ignore the drag enter event instead of accepting the proposed action.