Drag'n'Drop does not work after havin called QMainWindow::showFullScreen()
Hi everyone,
it seems as if drops are not being accepted by qmainwindows (or their child widgets), that have called showFullscreen() once.
Calling setAcceptDrops(true) after the showFullscreen() call does not help.
Other MainWindows do still accept the drops, which have been dragged from the misfunctioning MainWindow.
I tried to code a minimal example which shows the problem:
mainwindow.cpp:
Code:
#include "mainwindow.h"
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QLabel>
#include <QVBoxLayout>
#include <QPushButton>
class DragDropWidget
: public QWidget {public:
};
MainWindow
::MainWindow(QWidget *parent
) :{
widget1 = new DragDropWidget("1", this);
widget2 = new DragDropWidget("2", this);
l->addWidget(widget1);
l->addWidget(widget2);
connect(fullscreen, SIGNAL(clicked()), this, SLOT(onPushButtonClicked()));
l->addWidget(fullscreen);
central->setLayout(l);
setCentralWidget(central);
}
void MainWindow::onPushButtonClicked()
{
if(isFullScreen()) {
showNormal();
widget1->setAcceptDrops(true);
}
else {
showFullScreen();
widget1->setAcceptDrops(true);
}
}
DragDropWidget
::DragDropWidget(const QString &text,
QWidget *parent
) :{
setStyleSheet("QWidget { border: 1px solid blue; }");
setLayout(l);
label
= new QLabel(text,
this);
l->addWidget(label);
setAcceptDrops(true);
}
{
if(event->mimeData()->hasFormat("application/mimeType")) {
setStyleSheet("QWidget { border: 1px solid red; }");
event->acceptProposedAction();
}
}
{
QByteArray encodedData
= event
->mimeData
()->data
("application/mimeType");
stream >> data;
label->setText(data);
event->accept();
setStyleSheet("QWidget { border: 1px solid blue; }");
}
{
setStyleSheet("QWidget { border: 1px solid blue; }");
}
{
stream << label->text();
mimeData->setData("application/mimeType", encodedData);
drag->setMimeData(mimeData);
drag->exec();
}
mainwindow.h:
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class DragDropWidget;
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
private slots:
void onPushButtonClicked();
private:
DragDropWidget *widget1;
DragDropWidget *widget2;
};
#endif // MAINWINDOW_H
main.cpp
Code:
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
MainWindow w2;
w2.show();
return a.exec();
}
You can download the full project here: https://dl.dropbox.com/u/140012/drag...fullscreen.zip
Do I miss something here? I cant be the first person, who has this problem.
Thank you.
Re: Drag'n'Drop does not work after havin called QMainWindow::showFullScreen()
Your test project works fine for me (Linux, KDE, Qt 4.8.1).
Re: Drag'n'Drop does not work after havin called QMainWindow::showFullScreen()
I am on Mac OS X 10.7.4 and Qt 4.8.1.
And I found a workaround to the problem. You have to set acceptDrops to true on the QMainWindow instead its child widget, after calling showFullScreen:
Code:
void MainWindow::onPushButtonClicked()
{
if(isFullScreen()) {
showNormal();
}
else {
showFullScreen();
setAcceptDrops(true);
}
}
Is this wanted behaviour? If so: Why?
I would love to test this against a current Qt5 build. But the latest clone from git does not build on my system.