QX11EmbedContainer Drag and Drop



  • Drag and drop events are not working properly for an QX11EmbedContainer with a QX11EmbedWidget inside. The drag and drop events are received correctly when only the QX11EmbedWidget is shown. Any ideas?

    Thanks.



  • The code of the EmbedContainer is as follows
    @
    #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&#40;&#41;;
    process.close();
    return status;
    

    }@



  • The Embed Widget is divided into a main function and class:

    --------------------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();
    }

    void EmbedWidget::dropEvent(QDropEvent *event)
    {
    event->accept();
    }

    void EmbedWidget::paintEvent(QPaintEvent *event)
    {
    QPainter painter;
    painter.begin(this);
    painter.setRenderHint(QPainter::Antialiasing);
    painter.fillRect(event->rect(), QBrush(gradient));
    painter.end();
    }
    @



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.