Qt47::Drag&Drop events using eventFilter
-
Hello,
using QListView I installed a filter which is printing all events' received for the QListView object.
ThesetDragEnabled(true)
setAcceptDrops(true)were executed on the QListView object.
At first there were DragEnter (60) events received. But after several app. executions there were no drag&drop events received.
Is this a bug in QT 4.7?
-
can you post some related code please.
-
Between, I'd started the app. again and the event 60 was caught! It works time to time.
The methods are called in a constructor of the event_dlg object.
@void event_dlg::tune_listview()
{
events_listview_raw_ptr->setModel(events_list_model_raw_ptr);
events_listview_raw_ptr->setFixedWidth(events_listview_width);
events_listview_raw_ptr->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
events_listview_raw_ptr->setDragEnabled(true);
events_listview_raw_ptr->setAcceptDrops(true);
events_listview_raw_ptr->setDropIndicatorShown(true);
}@
@events_listview_raw_ptr->installEventFilter(this);@@event_dlg::~event_dlg()
{
events_listview_raw_ptr->removeEventFilter(this);
}@
@bool event_dlg::eventFilter(QObject *watched_raw_ptr, QEvent *event_raw_ptr)
{
if ( watched_raw_ptr != nullptr && event_raw_ptr != nullptr)
if ( watched_raw_ptr == events_listview_raw_ptr )
{
qDebug() << "listview raw pointer is filtered => " << event_raw_ptr->type();
//synchronize_view_and_model();
return false;
}
return QDialog::eventFilter( watched_raw_ptr, event_raw_ptr );
}@ -
you are only checking the listview itself. But the events get sent to it's viewport instead (which propagate them to the listview itself if not processed).
So install an eventfilter on the viewport of the listview and you will see the "missing" events. -
Yes. What is the difference between the viewport and the widget itself?
[quote author="raven-worx" date="1379404414"]you are only checking the listview itself. But the events get sent to it's viewport instead (which propagate them to the listview itself if not processed).
So install an eventfilter on the viewport of the listview and you will see the "missing" events.[/quote] -
This might help a bit : "What’s relationship between viewport(), widget() and QScrollArea":http://qt-project.org/forums/viewthread/3427
-
One solution is to create your own custom listView and override some of the methods like
@void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
void startDrag(Qt::DropActions supportedActions);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);@You can also check the following examples
- "Draggable Icons Example":http://qt-project.org/doc/qt-4.8/draganddrop-draggableicons.html
- "Drag and Drop Puzzle Example":http://qt-project.org/doc/qt-4.8/draganddrop-puzzle.html
-
dragEnterEvent is the default action for the QEvent::DragEnter in the QListView type if I am not mistaken.
Probably the startDrag should be the right choice. The "QAbstractItemView documentation":http://harmattan-dev.nokia.com/docs/library/html/qt4/qabstractitemview.html?tab=3&q=QListView#startDrag
does not provide such information. -
[quote author="Sam" date="1379412553"]One solution is to create your own custom listView and override some of the methods like
@void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
void startDrag(Qt::DropActions supportedActions);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);@
[/quote]Better override QAbstractItemView::viewportEvent() or it will result in the initial problem.
-
Could you explain why (in details)?
[quote author="raven-worx" date="1379413191"][quote author="Sam" date="1379412553"]One solution is to create your own custom listView and override some of the methods like@void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dropEvent(QDropEvent *event);
void startDrag(Qt::DropActions supportedActions);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);@
[/quote]Better override QAbstractItemView::viewportEvent() or it will result in the initial problem.
[/quote]
-
[quote author="silex92" date="1379413278"]Could you explain why (in details)?
[/quote]
When you look into the Qt source code you will see that viewportEvent() is actually the same like we already came up in the posts before (eventfilter on the viewport). When subclassing use this method instead of an eventfilter.[quote author="silex92" date="1379413166"]dragEnterEvent is the default action for the QEvent::DragEnter in the QListView type if I am not mistaken.
Probably the startDrag should be the right choice. The "QAbstractItemView documentation":http://harmattan-dev.nokia.com/docs/library/html/qt4/qabstractitemview.html?tab=3&q=QListView#startDrag
does not provide such information.[/quote]What exactly do you want to achieve actually?
-
There's a QListView and additional view - QStackedWidget which provides the actual information for each QListView object.
Hence, the pages(QStackedWidget) should be synchronized manually.
When the pages' information is input by an user, the model is not updated. Hence, before the mimeData method is invoked the model should be updated.
[quote author="raven-worx" date="1379413166"]
What exactly do you want to achieve actually?
[/quote] -
so you just need to update the model as soon as something changes in your "pages" right?
-
[quote author="silex92" date="1379414823"]The model should be updated only if an event is dragged.
[/quote]Then listen for the drag-enter event.