razdraz
14th June 2015, 13:04
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:
class myQListWidget:public QListWidget
{
Q_OBJECT
public:
myQListWidget(QWidget * parent = 0);
~myQListWidget();
protected:
void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
};
.cpp:
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;
}
When using the original QListWidget class, the cursor does not change to "forbidden" and drops work properly.
What am I missing here?
Thanks.
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:
class myQListWidget:public QListWidget
{
Q_OBJECT
public:
myQListWidget(QWidget * parent = 0);
~myQListWidget();
protected:
void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
};
.cpp:
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;
}
When using the original QListWidget class, the cursor does not change to "forbidden" and drops work properly.
What am I missing here?
Thanks.