PDA

View Full Version : QX11EmbedContainer Drag and Drop



Tweety66
13th May 2013, 14:15
Drag and drop events aren´t working for QX11EmbedContainer. Any ideas? The acceptDrop property is enabled.

Tweety66
14th May 2013, 12:42
The application of the QX11EmbedContainer is the following:


#include <QtGui>
#include <QX11EmbedContainer>

//! [0]
int main(int argc, char *argv[])
{
QApplication app(argc, argv);

if (app.arguments().count() != 2) {
qFatal("Error - expected executable path as argument");
return 1;
}

QX11EmbedContainer container;
container.show();
container.setAcceptDrops(true);
QProcess process(&container);
QString executable(app.arguments()[1]);
QStringList arguments;
arguments << QString::number(container.winId());
process.start(executable, arguments);

int status = app.exec();
process.close();
return status;
}

The QX11EmbedWidget application is divided into a main function and EmbedWidget class. The EmbedWidget class inherits QX11EmbedWidget and implements the drag and drop events.

------------------------------main.cpp------------------------------------------

#include <QApplication>
#include <QWidget>
#include <QDebug>
#include "embedwidget.h"

//! [0]
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
EmbedWidget window;
if (app.arguments().count() != 2)
{
window.show();
}
else
{
QString windowId(app.arguments()[1]);
window.embedInto(windowId.toULong());
window.show();
}

return app.exec();
}

-------------------------------embedwidget.h-------------------------------------------
#ifndef EMBEDWIDGET_H
#define EMBEDWIDGET_H

#include <QRadialGradient>
#include <QSize>
#include <QX11EmbedWidget>

class QPaintEvent;

class EmbedWidget : public QX11EmbedWidget
{
Q_OBJECT

public:
EmbedWidget(QWidget *parent = 0);
QSize sizeHint() const;
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dragLeaveEvent(QDragLeaveEvent *event);
void dropEvent(QDropEvent *event);

protected:
void paintEvent(QPaintEvent *event);

private:
QRadialGradient gradient;
};

#endif

---------------------------------EmbedWidget.cpp---------------------------------------

#include <QtGui>
#include <QDragEnterEvent>

#include "embedwidget.h"

EmbedWidget::EmbedWidget(QWidget *parent)
: QX11EmbedWidget(parent)
{
gradient = QRadialGradient(100, 100, 90, 60, 60);
gradient.setColorAt(0.0, Qt::white);
gradient.setColorAt(0.9, QColor(192, 192, 255));
gradient.setColorAt(1.0, QColor(0, 32, 64));
setAcceptDrops(true);
}



QSize EmbedWidget::sizeHint() const
{
return QSize(600, 600);
}

void EmbedWidget::dragEnterEvent(QDragEnterEvent *event)
{

event->accept();
}

void EmbedWidget::dragMoveEvent(QDragMoveEvent *event)
{
event->accept();
}

void EmbedWidget::dragLeaveEvent(QDragLeaveEvent *event)
{
event->accept();
}

Added after 6 minutes:

The embedwidget accepts all the drag and drop events correctly when executed separately from the container. This does not work properly when the process is executed inside the container.

agentbauer024
26th June 2013, 19:19
Hello,

Any luck with this? We are experiencing the same issue. Additionally, we notice that wreckless dragging outside of the container's window will cause one or both programs to crash.

Thanks,
Kurt

olzzen
12th October 2015, 09:50
Hello,

i'am facing the same problem. There are no DnD-related events being propagated. Furthermore i cannot handle contextmenu-events.

Has anybody an idea? Is there a BUG in Qt?

greetz