M
M
Mikhail Burilov2014-02-27 07:20:11
Qt
Mikhail Burilov, 2014-02-27 07:20:11

Why doesn't drag&drop work in qt5?

OS - Windows 8.1 x64, msvc2010 compiler, drag&drop does not work categorically.
In my application I do setAcceptDrops(true), override methods
void dragEnterEvent(QDragEnterEvent* event);
void dragMoveEvent(QDragMoveEvent* event);
void dragLeaveEvent(QDragLeaveEvent* event);
void dropEvent(QDropEvent* event);
none of the methods are called.
I'm compiling a dropsite example from sdk, it doesn't work. What could be the problem?
checked - the same example on the same computer, but it works in qt 4.8.
at the request of the workers - a piece of code from the example:

DropArea::DropArea(QWidget *parent)
    : QLabel(parent)
{
    setMinimumSize(200, 200);
    setFrameStyle(QFrame::Sunken | QFrame::StyledPanel);
    setAlignment(Qt::AlignCenter);
    setAcceptDrops(true);
    setAutoFillBackground(true);
    clear();
}

void DropArea::dragEnterEvent(QDragEnterEvent *event)
{
    setText(tr("<drop content>"));
    setBackgroundRole(QPalette::Highlight);

    event->acceptProposedAction();
    emit changed(event->mimeData());
}

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

void DropArea::dropEvent(QDropEvent *event)
{
    const QMimeData *mimeData = event->mimeData();
    if (mimeData->hasImage()) {
        setPixmap(qvariant_cast<QPixmap>(mimeData->imageData()));
    } else if (mimeData->hasHtml()) {
        setText(mimeData->html());
        setTextFormat(Qt::RichText);
    } else if (mimeData->hasText()) {
        setText(mimeData->text());
        setTextFormat(Qt::PlainText);
    } else if (mimeData->hasUrls()) {
        QList<QUrl> urlList = mimeData->urls();
        QString text;
        for (int i = 0; i < urlList.size() && i < 32; ++i) {
            QString url = urlList.at(i).path();
            text += url + QString("\n");
        }
        setText(text);
    } else {
        setText(tr("Cannot display data"));
    }
    setBackgroundRole(QPalette::Dark);
    event->acceptProposedAction();
}
void DropArea::dragLeaveEvent(QDragLeaveEvent *event)
{
    clear();
    event->accept();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DancingOnWater, 2014-02-28
@DancingOnWater

Hmm, then look in the Qt bugtracker, well, try to link the Qt debug libs And see what the difference is for qt5 and qt4.8
My Win7 configuration Qt 5.2.1 built on MinGW and everything works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question