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:
#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();
}
#include "mainwindow.h"
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QLabel>
#include <QVBoxLayout>
#include <QPushButton>
class DragDropWidget : public QWidget {
public:
DragDropWidget(const QString &text, QWidget *parent);
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
void dragLeaveEvent(QDragLeaveEvent *);
void mousePressEvent(QMouseEvent *event);
QLabel *label;
};
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QWidget *central = new QWidget(this);
QVBoxLayout *l = new QVBoxLayout(central);
widget1 = new DragDropWidget("1", this);
widget2 = new DragDropWidget("2", this);
l->addWidget(widget1);
l->addWidget(widget2);
QPushButton *fullscreen = new QPushButton(this);
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) :
QWidget(parent)
{
setStyleSheet("QWidget { border: 1px solid blue; }");
QVBoxLayout *l = new QVBoxLayout(this);
setLayout(l);
label = new QLabel(text, this);
l->addWidget(label);
setAcceptDrops(true);
}
void DragDropWidget::dragEnterEvent(QDragEnterEvent *event)
{
if(event->mimeData()->hasFormat("application/mimeType")) {
setStyleSheet("QWidget { border: 1px solid red; }");
event->acceptProposedAction();
}
}
void DragDropWidget::dropEvent(QDropEvent *event)
{
QByteArray encodedData = event->mimeData()->data("application/mimeType");
QDataStream stream(&encodedData, QIODevice::ReadOnly);
QString data;
stream >> data;
label->setText(data);
event->accept();
setStyleSheet("QWidget { border: 1px solid blue; }");
}
void DragDropWidget::dragLeaveEvent(QDragLeaveEvent *)
{
setStyleSheet("QWidget { border: 1px solid blue; }");
}
void DragDropWidget::mousePressEvent(QMouseEvent *)
{
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
stream << label->text();
mimeData->setData("application/mimeType", encodedData);
drag->setMimeData(mimeData);
drag->exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.h:
#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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class DragDropWidget;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
private slots:
void onPushButtonClicked();
private:
DragDropWidget *widget1;
DragDropWidget *widget2;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
MainWindow w2;
w2.show();
return a.exec();
}
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
MainWindow w2;
w2.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks