Results 1 to 20 of 27

Thread: QDropEvent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    129

    Default Re: QDropEvent

    Wysota

    i have gone through the below link

    http://www.qtsoftware.com/developer/...-23.4700087965..

    same thing only i followed ...please i request you provide me one sample example


    Thanks

    Addu R

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

    Default Re: QDropEvent

    Learn, don't copy without thinking.
    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
    May 2009
    Posts
    129

    Default Re: QDropEvent

    I am trying to execute sample example.. while executing i am getting following errors

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include <QTreeWidgetItem>
    6. #include <QMimeData>
    7.  
    8. namespace Ui
    9. {
    10. class MainWindowClass;
    11. }
    12.  
    13. class MainWindow : public QMainWindow
    14. {
    15. Q_OBJECT
    16.  
    17. public:
    18. MainWindow(QWidget *parent = 0);
    19. ~MainWindow();
    20. bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action);
    21. QMimeData *mimeData(const QList<QTreeWidgetItem *> items) const;
    22. private:
    23. Ui::MainWindowClass *ui;
    24. protected:
    25. void dragEnterEvent(QDragEnterEvent e);
    26. void dragMoveEvent(QDragMoveEvent e) ;
    27.  
    28.  
    29. };
    30.  
    31. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    mainwindow.cpp

    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QMessageBox>
    4. MainWindow::MainWindow(QWidget *parent)
    5. : QMainWindow(parent), ui(new Ui::MainWindowClass)
    6. {
    7. ui->setupUi(this);
    8. ui->treeWidget->setColumnCount(2);
    9. ui->treeWidget->setAcceptDrops( true );
    10. // The tree supports dragging of its own items
    11. ui->treeWidget->setDragEnabled(true);
    12. QTreeWidgetItem *itemOne = new QTreeWidgetItem(ui->treeWidget);
    13. QTreeWidgetItem *itemTwo = new QTreeWidgetItem(ui->treeWidget);
    14. QTreeWidgetItem *itemThree = new QTreeWidgetItem(ui->treeWidget);
    15.  
    16. itemOne->setText(0, "John");
    17. itemTwo->setText(0, "Peter");
    18. itemThree->setText(0, "Kumar");
    19. }
    20.  
    21. MainWindow::~MainWindow()
    22. {
    23. delete ui;
    24. }
    25. QMimeData *MainWindow::mimeData(const QList<QTreeWidgetItem *> items) const
    26. {
    27. // Create a QByteArray to store the data for the drag.
    28. QByteArray text;
    29. // Create a data stream that operates on the binary data
    30. QDataStream ds(&text, QIODevice::WriteOnly);
    31. // Add each item's text for col 0 to the stream
    32. for (int i=0;i<items.size();i++)
    33. ds << items.at(i)->text(0);
    34. QMimeData *md = new QMimeData;
    35. // Set the data associated with the mime type foo/bar to ba
    36. md->setData("foo/bar", text);
    37. return md;
    38. }
    39. bool MainWindow::dropMimeData(QTreeWidgetItem *parent, int index, const
    40. QMimeData *data, Qt::DropAction action)
    41. {
    42. if (parent) {
    43. // Create a QByteArray from the mimedata associated with foo/bar
    44. QByteArray text = data->data("foo/bar");
    45. // Create a data stream that operates on the binary data
    46. QDataStream ds(&text, QIODevice::ReadOnly);
    47. while (!ds.atEnd()) {
    48. QString str;
    49. // Read a byte from the stream into the string
    50. ds >> str;
    51. // Create a new item that has the item that is dropped on as a parent
    52.  
    53. QTreeWidgetItem *newItem = new QTreeWidgetItem(parent);
    54. newItem->setText(0, str);
    55. }
    56. }
    57. return true;
    58. }
    59. void MainWindow::dragEnterEvent(QDragEnterEvent event)
    60. {
    61. event.accept();
    62. }
    63.  
    64.  
    65. void MainWindow::dragMoveEvent(QDragMoveEvent event)
    66. {
    67. event.accept();
    68. }
    To copy to clipboard, switch view to plain text mode 

    errors:
    error: `event' has incomplete type
    error: forward declaration of `struct QDragEnterEvent'
    error: invalid use of undefined type `struct QDragEnterEvent'
    error: forward declaration of `struct QDragEnterEvent'
    error: `event' has incomplete type

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

    Default Re: QDropEvent

    You didn't include proper files so the compiler complains about it.
    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.


  5. #5
    Join Date
    May 2009
    Posts
    129

    Default Re: QDropEvent

    Hi wysota

    In above example .. when running the application mimedata, Dropmimedata is never invoked..

    I put the QmessageBox and qDebug() statement there.. But i didn't get any responce from that functions..


    Thanks

    Yuvaraj R

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

    Default Re: QDropEvent

    It will never be invoked because you're overriding the whole drag&drop mechanism present in Item Views. And you still didn't bother to read the docs...
    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.


  7. #7
    Join Date
    May 2009
    Posts
    129

    Default Re: QDropEvent

    Hi wysota..

    I have been reading the doc and right now i am referring the item/view based Puzzle example...

    whenever make drag the data are stored at time mime data function will be called ..

    whenver we dropping the item that time dropmime data function will be called..

    if i don't override drag and drop functions also that two functions are not invoking...



    Thanks

    Addu R

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

    Default Re: QDropEvent

    You only need to override mimeData() and dropMimeData(), nothing more.
    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.


  9. #9
    Join Date
    May 2009
    Posts
    129

    Default Re: QDropEvent

    Dear Wysota

    I over ride the drag and drop function by setting the QTreeWidget class as a parent..

    sample code

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3. #include <QTreeWidgetItem>
    4. #include <QtGui/QMainWindow>
    5. #include <QDropEvent>
    6. namespace Ui
    7. {
    8. class MainWindowClass;
    9. }
    10.  
    11. class MainWindow : public QMainWindow,public QTreeWidget
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. MainWindow(QWidget *parent = 0);
    17. ~MainWindow();
    18. bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action);
    19. QMimeData *mimeData(const QList<QTreeWidgetItem *> items) const;
    20. void dragEnterEvent(QDragEnterEvent *e);
    21. void dragMoveEvent(QDragMoveEvent *e) ;
    22. private:
    23. Ui::MainWindowClass *ui;
    24.  
    25. };
    26.  
    27. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 
    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QMessageBox>
    4. MainWindow::MainWindow(QWidget *parent)
    5. : QMainWindow(parent),QTreeWidget(parent), ui(new Ui::MainWindowClass)
    6. {
    7. ui->setupUi(this);
    8. ui->treeWidget->setColumnCount(1);
    9. ui->treeWidget->setAcceptDrops( true );
    10. // The tree supports dragging of its own items
    11. ui->treeWidget->setDragEnabled(true);
    12. QTreeWidgetItem *itemOne = new QTreeWidgetItem(ui->treeWidget);
    13. QTreeWidgetItem *itemTwo = new QTreeWidgetItem(ui->treeWidget);
    14. QTreeWidgetItem *itemThree = new QTreeWidgetItem(ui->treeWidget);
    15. itemOne->setText(0, "John");
    16. itemTwo->setText(0, "Peter");
    17. itemThree->setText(0, "Kumar");
    18. }
    19. QMimeData *MainWindow::mimeData(const QList<QTreeWidgetItem *> items) const
    20. {
    21. QMessageBox::information(0,"",QString("Drag and Drop"));
    22. // Create a QByteArray to store the data for the drag.
    23. QByteArray text;
    24. // Create a data stream that operates on the binary data
    25. QDataStream ds(&text, QIODevice::WriteOnly);
    26. // Add each item's text for col 0 to the stream
    27. for (int i=0;i<items.size();i++)
    28. ds << items.at(i)->text(0);
    29. QMimeData *md = new QMimeData;
    30. // Set the data associated with the mime type foo/bar to ba
    31. md->setData("foo/bar", text);
    32. return md;
    33. }
    34. bool MainWindow::dropMimeData(QTreeWidgetItem *parent, int index, const
    35. QMimeData *data, Qt::DropAction action)
    36. {
    37.  
    38. if (parent) {
    39. // Create a QByteArray from the mimedata associated with foo/bar
    40. QByteArray text = data->data("foo/bar");
    41. // Create a data stream that operates on the binary data
    42. QDataStream ds(&text, QIODevice::ReadOnly);
    43. while (!ds.atEnd()) {
    44. QString str;
    45. // Read a byte from the stream into the string
    46. ds >> str;
    47. // Create a new item that has the item that is dropped on as a parent
    48.  
    49. QTreeWidgetItem *newItem = new QTreeWidgetItem(parent);
    50. newItem->setText(0, str);
    51. }
    52. }
    53. return true;
    54. }
    55. void MainWindow::dragEnterEvent(QDragEnterEvent *e)
    56. {
    57. e->accept();
    58. }
    59.  
    60.  
    61. void MainWindow::dragMoveEvent(QDragMoveEvent *e)
    62. {
    63. e->accept();
    64. }
    65.  
    66. MainWindow::~MainWindow()
    67. {
    68. delete ui;
    69. }
    To copy to clipboard, switch view to plain text mode 


    I have one doubt .,Mainwindow class having two sub classes.which sub class drag enter & drag move functions it will take..

    please clear me

    Thanks

    Addu R

  10. #10
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDropEvent

    hey man.. u cannot inherit from both QMainWindow and QTreeWidget. make seperate classes for both of them.. ..
    tomoro if i get the Fkin time i will read your posts and problems..

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

    Default Re: QDropEvent

    Quote Originally Posted by addu View Post
    Qt Code:
    1. class MainWindow : public QMainWindow,public QTreeWidget
    To copy to clipboard, switch view to plain text mode 
    Ah man.... did you even try to compile this code?

    At moments like this I'm beginning to think if we're even remotely close to managing to educate people here...

    Maybe we should get some programming certification scheme here or something...
    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.


  12. #12
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDropEvent

    what i found is many ppl know c++ but do not know one of these concepts 1. inheritance 2. virtual 3. pointers. And they jump into Qt. This where all starts to mess up.

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

    Default Re: QDropEvent

    Quote Originally Posted by MrDeath View Post
    what i found is many ppl know c++ but do not know one of these concepts 1. inheritance 2. virtual 3. pointers.
    It's like "they know how to drive but only on the first gear and only straight ahead". It's hard to call it "knowing how to drive" then... But that you don't know how to program is not a big deal. It starts to be a deal when you're not learning and still continue to bang your head against the wall.
    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.


  14. #14
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDropEvent

    Quote Originally Posted by MrDeath View Post
    ...but do not know one of these concepts...
    and sometimes not only one :P
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. May I get XEvent from QDropEvent?
    By alfa_wu in forum Qt Programming
    Replies: 4
    Last Post: 19th March 2007, 01:43

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
  •  
Qt is a trademark of The Qt Company.