Results 1 to 3 of 3

Thread: Drag'n'Drop does not work after havin called QMainWindow::showFullScreen()

  1. #1
    Join Date
    Dec 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default 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:
    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. #include <QDragEnterEvent>
    4. #include <QDropEvent>
    5. #include <QLabel>
    6. #include <QVBoxLayout>
    7. #include <QPushButton>
    8.  
    9. class DragDropWidget : public QWidget {
    10. public:
    11. DragDropWidget(const QString &text, QWidget *parent);
    12. void dragEnterEvent(QDragEnterEvent *event);
    13. void dropEvent(QDropEvent *event);
    14. void dragLeaveEvent(QDragLeaveEvent *);
    15. void mousePressEvent(QMouseEvent *event);
    16.  
    17. QLabel *label;
    18. };
    19.  
    20. MainWindow::MainWindow(QWidget *parent) :
    21. QMainWindow(parent)
    22. {
    23. QWidget *central = new QWidget(this);
    24. QVBoxLayout *l = new QVBoxLayout(central);
    25.  
    26. widget1 = new DragDropWidget("1", this);
    27. widget2 = new DragDropWidget("2", this);
    28.  
    29. l->addWidget(widget1);
    30. l->addWidget(widget2);
    31.  
    32. QPushButton *fullscreen = new QPushButton(this);
    33. connect(fullscreen, SIGNAL(clicked()), this, SLOT(onPushButtonClicked()));
    34. l->addWidget(fullscreen);
    35.  
    36. central->setLayout(l);
    37. setCentralWidget(central);
    38. }
    39.  
    40. void MainWindow::onPushButtonClicked()
    41. {
    42. if(isFullScreen()) {
    43. showNormal();
    44. widget1->setAcceptDrops(true);
    45. }
    46. else {
    47. showFullScreen();
    48. widget1->setAcceptDrops(true);
    49. }
    50. }
    51.  
    52. DragDropWidget::DragDropWidget(const QString &text, QWidget *parent) :
    53. QWidget(parent)
    54. {
    55. setStyleSheet("QWidget { border: 1px solid blue; }");
    56. QVBoxLayout *l = new QVBoxLayout(this);
    57. setLayout(l);
    58. label = new QLabel(text, this);
    59. l->addWidget(label);
    60. setAcceptDrops(true);
    61. }
    62.  
    63. void DragDropWidget::dragEnterEvent(QDragEnterEvent *event)
    64. {
    65. if(event->mimeData()->hasFormat("application/mimeType")) {
    66. setStyleSheet("QWidget { border: 1px solid red; }");
    67. event->acceptProposedAction();
    68. }
    69. }
    70.  
    71. void DragDropWidget::dropEvent(QDropEvent *event)
    72. {
    73. QByteArray encodedData = event->mimeData()->data("application/mimeType");
    74. QDataStream stream(&encodedData, QIODevice::ReadOnly);
    75. QString data;
    76. stream >> data;
    77. label->setText(data);
    78. event->accept();
    79. setStyleSheet("QWidget { border: 1px solid blue; }");
    80. }
    81.  
    82. void DragDropWidget::dragLeaveEvent(QDragLeaveEvent *)
    83. {
    84. setStyleSheet("QWidget { border: 1px solid blue; }");
    85. }
    86.  
    87. void DragDropWidget::mousePressEvent(QMouseEvent *)
    88. {
    89. QDrag *drag = new QDrag(this);
    90. QMimeData *mimeData = new QMimeData;
    91.  
    92. QByteArray encodedData;
    93. QDataStream stream(&encodedData, QIODevice::WriteOnly);
    94. stream << label->text();
    95.  
    96. mimeData->setData("application/mimeType", encodedData);
    97. drag->setMimeData(mimeData);
    98. drag->exec();
    99. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h:
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. class DragDropWidget;
    7.  
    8. class MainWindow : public QMainWindow
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. explicit MainWindow(QWidget *parent = 0);
    14.  
    15. private slots:
    16. void onPushButtonClicked();
    17.  
    18. private:
    19. DragDropWidget *widget1;
    20. DragDropWidget *widget2;
    21. };
    22. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9.  
    10. MainWindow w2;
    11. w2.show();
    12.  
    13. return a.exec();
    14. }
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2010
    Posts
    11
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default 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:

    Qt Code:
    1. void MainWindow::onPushButtonClicked()
    2. {
    3. if(isFullScreen()) {
    4. showNormal();
    5. }
    6. else {
    7. showFullScreen();
    8. setAcceptDrops(true);
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    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.

Similar Threads

  1. Replies: 1
    Last Post: 13th October 2011, 14:59
  2. Replies: 4
    Last Post: 24th August 2011, 22:33
  3. ShowFullScreen on QStackWidget don't work
    By Ratheendrans in forum Qt Programming
    Replies: 2
    Last Post: 10th May 2010, 18:34
  4. Can't get Drag and Drop capability work.
    By HeX0R in forum Newbie
    Replies: 1
    Last Post: 28th March 2010, 00:30
  5. Drag and Drop, dropEvent not being called?
    By steg90 in forum Qt Programming
    Replies: 36
    Last Post: 22nd May 2007, 07:03

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.