Commit 2df18ec3 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Fix drag and drop

The release mouse event does not come through if we start a drag.
There was already a workaround that stopped working with 5.8 and
did rely on private API.
I removed all usage of private API and added a simple workaround
that synthesises a mouse release event.

The actual execution of the drag is now asynchronous to
ensure the release event is delivered properly.

I removed all dependencies on private API in the designer.

In Qt 5.9 the issue seems to be fixed in Qt.
The workaround does not seem to get in the way of the fix.
Eventually, the workaround can be removed.

Change-Id: I9b45b255da5e44c26aba2acf4a42f88537126f75
Reviewed-by: Tim Jenssen's avatarTim Jenssen <>
parent 975c283e
......@@ -73,12 +73,8 @@ Item {
id: mouseRegion
anchors.fill: parent
property bool reallyPressed: false
property int pressedX
property int pressedY
onPressed: {
rootView.startDragAndDrop(mouseRegion, itemLibraryEntry)
......@@ -48,6 +48,7 @@
#include <QTabBar>
#include <QImageReader>
#include <QMimeData>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QMenu>
#include <QApplication>
......@@ -55,10 +56,6 @@
#include <QShortcut>
#include <QQuickItem>
#include <private/qquickwidget_p.h> // mouse ungrabbing workaround on quickitems
#include <private/qquickwindow_p.h> // mouse ungrabbing workaround on quickitems
namespace QmlDesigner {
ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
......@@ -265,14 +262,7 @@ void ItemLibraryWidget::setResourcePath(const QString &resourcePath)
static void ungrabMouseOnQMLWorldWorkAround(QQuickWidget *quickWidget)
const QQuickWidgetPrivate *widgetPrivate = QQuickWidgetPrivate::get(quickWidget);
if (widgetPrivate && widgetPrivate->offscreenWindow && widgetPrivate->offscreenWindow->mouseGrabberItem())
void ItemLibraryWidget::startDragAndDrop(QVariant itemLibraryId)
void ItemLibraryWidget::startDragAndDrop(QQuickItem *mouseArea, QVariant itemLibraryId)
m_currentitemLibraryEntry = itemLibraryId.value<ItemLibraryEntry>();
......@@ -283,9 +273,14 @@ void ItemLibraryWidget::startDragAndDrop(QVariant itemLibraryId)
/* Workaround for bug in Qt. The release event is not delivered for Qt < 5.9 if a drag is started */
QMouseEvent event (QEvent::MouseButtonRelease, QPoint(-1, -1), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
QApplication::sendEvent(mouseArea, &event);
QTimer::singleShot(0, [drag]() {
void ItemLibraryWidget::removeImport(const QString &name)
......@@ -84,7 +84,7 @@ public:
void setModel(Model *model);
Q_INVOKABLE void startDragAndDrop(QVariant itemLibId);
Q_INVOKABLE void startDragAndDrop(QQuickItem *mouseArea, QVariant itemLibId);
void removeImport(const QString &name);
QT += quickwidgets
QT += widgets-private quick-private quickwidgets-private core-private gui-private #mouse ungrabbing workaround on quickitems
CONFIG += exceptions
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment