Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeWidgen in QDockWidget doesn't receive dragEnterEvent when it is undocked
Forum Updated to NodeBB v4.3 + New Features

QTreeWidgen in QDockWidget doesn't receive dragEnterEvent when it is undocked

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ChanchoCiego
    wrote on last edited by
    #1

    Hello, good day,

    I have a QTreeWidgen within a QDockWidget that when docked receives and processes of Drag & Drop events correctly, but when it is undocked you receive nothing. Is this normal?

    This is the statement:

    @
    class ListaWidget : public QListWidget
    {
    Q_OBJECT

    QPoint              dragStartPosition;
    

    public:

    ListaWidget(QString nombre, QWidget *parent) : QListWidget(parent)
    {
        this->setIconSize(QSize(24,24));
        this->setFlow(QListView::LeftToRight);
        this->setWrapping(true);
        this->setViewMode(QListView::IconMode);
        this->setResizeMode(QListView::Adjust);
        this->setWordWrap(true);
        this->setObjectName(nombre);
        setDragEnabled(true);
        setAcceptDrops(true);
    }
    
    void dragEnterEvent(QDragEnterEvent *event);
    void dragMoveEvent(QDragMoveEvent *event);
    void dragLeaveEvent(QDragLeaveEvent *event);
    void dropEvent(QDropEvent *event);
    
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    

    signals:
    void informacion(QString info);
    };
    @

    And this is the implementation:

    @
    //-----------------------------------------------------------------------------

    void ListaWidget::mousePressEvent(QMouseEvent *event)
    {
    emit informacion("void ListaWidget::mousePressEvent(QMouseEvent *event)");

    if (event->button() == Qt::LeftButton)
    {
        dragStartPosition = event->pos();
        emit informacion("\tQt::LeftButton");
    }
    else if ( event->button() == Qt::RightButton )
    {
        emit informacion("\tQt::RightButton");
    }
    

    }

    //-----------------------------------------------------------------------------

    void ListaWidget::mouseMoveEvent(QMouseEvent *event)
    {
    if (!(event->buttons() & Qt::LeftButton))
    return;
    if ((event->pos() - dragStartPosition).manhattanLength()
    < QApplication::startDragDistance())
    return;

    emit informacion("void ListaWidget::mouseMoveEvent(QMouseEvent *event)");
    
    QDrag *drag = new QDrag(this);
    QMimeData *mimeData = new QMimeData;
    
    QList <QUrl> urls;
    QUrl url("file:///E:/Descargas/dcpcrypt2-xe-update2.zip");
    
            emit informacion("\turls.append(url);");
    urls.append(url);
            emit informacion("\tmimeData->setText(this->objectName());");
    mimeData->setText(this->objectName());
            emit informacion("\tmimeData->setUrls(urls);");
    mimeData->setUrls(urls);
            emit informacion("\tdrag->setMimeData(mimeData);");
    drag->setMimeData(mimeData);
    
            emit informacion("\tdrag->exec&#40;Qt::CopyAction&#41;;");
    drag->exec&#40;Qt::CopyAction&#41;;
            emit informacion("\t######## FIN ########");
    

    }

    //-----------------------------------------------------------------------------

    void ListaWidget::dragEnterEvent(QDragEnterEvent *event)
    {
    event->acceptProposedAction();
    }

    //-----------------------------------------------------------------------------

    void ListaWidget::dragMoveEvent(QDragMoveEvent *event)
    {
    event->acceptProposedAction();
    }

    //-----------------------------------------------------------------------------

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

    //-----------------------------------------------------------------------------

    void ListaWidget::dropEvent(QDropEvent *event)
    {
    emit informacion("void ListaWidget::dropEvent(QDropEvent *event)");

    if (event->mimeData()->hasText())
    {
        if (event->mimeData()->text() == this->objectName())
        {
            emit informacion("\tSALIENDO de void ListaWidget::dropEvent(QDropEvent *event)");
            return;
        }
    }
    
    // extrae los datos mime del evento
    const QMimeData *mimeData = event->mimeData();
    
    // identifica el dato mime recibido
    if (mimeData->hasImage())
        emit informacion(tr("\t######## Imagen ########"));
    else if (mimeData->hasHtml())
        emit informacion(tr("\t######## HTML : ") + mimeData->html());
    else if (mimeData->hasText())
        emit informacion(tr("\t######## TEXT : ") + mimeData->text());
    else if (mimeData->hasUrls())
    {
        QList<QUrl> urlList = mimeData->urls();
    
        emit informacion("------------------------------------");
        for (int i = 0; i < urlList.size() && i < 32; ++i)
        {
            emit informacion(tr("\t") + urlList.at(i).path());
        }
        emit informacion("------------------------------------");
    }
    else
        emit informacion(tr("No se pueden mostrar los datos"));
    
    for (int i=0; i<mimeData->formats().count(); i++)
        emit informacion("\t" + mimeData->formats().value(i));
    emit informacion("------------------------------------");
    
    event->acceptProposedAction();
    

    }

    //-----------------------------------------------------------------------------
    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved