Hello,
I'm relatively new to Qt and I have problems to implement drag&drop function to my derived QListWidget class. While the drag is working perfectly, the drop does't. The cursor changes to "forbidden" after dragging an Item.
For now, I just want to get the x-Axis position of the drag and drop point (Drag is working).
Derived class:
.h:
{
Q_OBJECT
public:
myQListWidget
(QWidget * parent
= 0);
~myQListWidget();
protected:
};
class myQListWidget:public QListWidget
{
Q_OBJECT
public:
myQListWidget(QWidget * parent = 0);
~myQListWidget();
protected:
void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
};
To copy to clipboard, switch view to plain text mode
.cpp:
myQListWidget
::myQListWidget(QWidget * parent
){
this->setAcceptDrops(true);
}
myQListWidget::~myQListWidget()
{
}
{
xPositionDrop = event->pos().rx();
qDebug() << "xPositionDrop: " << xPositionDrag;
}
{
xPositionDrag = event->pos().rx();
qDebug() << "xPositionDrag: " << xPositionDrag;
}
myQListWidget::myQListWidget(QWidget * parent)
{
this->setAcceptDrops(true);
this->setDragDropMode(QAbstractItemView::DragDrop);
}
myQListWidget::~myQListWidget()
{
}
void myQListWidget::dropEvent(QDropEvent *event)
{
xPositionDrop = event->pos().rx();
qDebug() << "xPositionDrop: " << xPositionDrag;
}
void myQListWidget::dragEnterEvent(QDragEnterEvent *event)
{
xPositionDrag = event->pos().rx();
qDebug() << "xPositionDrag: " << xPositionDrag;
}
To copy to clipboard, switch view to plain text mode
When using the original QListWidget class, the cursor does not change to "forbidden" and drops work properly.
What am I missing here?
Thanks.
Bookmarks