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 QDropEvent

    Hi All

    i am facing the same QTreeWidget Drag and Drop issue since last 1.5 weeks..

    I am feeling this is very bad me..

    My problem is How can i set top level items only has to accepts drops.

    I set following things

    ui->widget->dragDropOverwriteMode();
    ui->treeWidget->setDragEnabled(true);
    ui->treeWidget->setAcceptDrops(true);
    ui->treeWidget->setDragDropMode(QAbstractItemView ::InternalMove);


    I know answer is very simple, But i don't know how do compare the Drop Event with top level items ...

    please help me to sort out this issue..

    Any suggestions welcome.

    Thanks

    Addu R

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QDropEvent

    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

    Dear wysota

    Thanks for your reply..

    I enabled the Drop action only for top level items by

    QTreeWidgetItem * friends = new QTreewidgetItem(ui->treeWidget);

    freinds->setFlags(Qt::Items is Drop Enabled);

    but same thing all items are accepting the drops...

    And one more thing dafter dropping the any one item to friends ,it behaving like child item


    Thanks

    Addu R

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QDropEvent

    Make sure InternalMove is disabled. If that doesn't help, please provide a minimal compilable example reproducing the problem.
    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

    Previously i used the internalmove mode, Then i changed to DragDrop mode.. But it is not working for me ..

    sample code

    Qt Code:
    1. ui->treeWidget->dragDropOverwriteMode();
    2. ui->treeWidget->setDragEnabled(true);
    3. ui->treeWidget->setAcceptDrops(true);
    4. ui->treeWidget->setDragDropMode(QAbstractItemView ::DragDrop);
    5. QTreeWidgetItem *item = new QTreeWidgetItem(ui->treeWidget);
    6. item->setText(0,"Friends");
    7. QList <QString > list;
    8. list << tr("john") << tr("joseph") << tr("stephen") << tr("raj") << tr("Addu") ;
    9.  
    10. for ( int i=0;i < list.size;i++)
    11. {
    12. QTreeWidgetItem *new_item = new QTreeWidgetItem(item);
    13. new_item->setText(0,list.at(i));
    14. }
    To copy to clipboard, switch view to plain text mode 

    Again i am creating new top level item for TreeWidget

    Qt Code:
    1. QTreeWidgetItem *colleages = new QTreeWidgetItem(ui->treewidget);
    2. colleages->setText(0,"co-Workers");
    To copy to clipboard, switch view to plain text mode 

    I am trying to drag the items from friends to co-workers .. Here top level item only accept the drops..child items won't accept the drops.


    How do i sort out this issue


    Thanks

    Addu R

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QDropEvent

    Ok, but how do you set the flags and how do you handle the drop itself?
    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

    I set the flags only for top level items ..

    Qt Code:
    1. item->setFlag(Qt::ItemisDropEnabled);
    2. colleages->setFlag(Qt::ItemisDropEnabled);
    3. new_item->setFlag(Qt::Itemis DragEnabled);
    To copy to clipboard, switch view to plain text mode 

    Previoused i over ride the DropEvent function..
    But if i set the ui->treeWidget->setAcceptDrops(true),DropEvent function was not called ..

    So I commented the DropEvent function..

    And i did like this

    Qt Code:
    1. void MainWindow::dropEvent(QDropEvent *event)
    2. {
    3. ui->treeWidget->setDropEvent(event) // Here Application is crashing
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 

    Where i have done mistake,please correct me, i know problem is at DropEvent function..

    please help me to clear this issue

    Thanks

    Addu R

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QDropEvent

    The mistake you did was that you didn't bother to look into the documentation.

    QTreeWidget::dropMimeData()
    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..

    Thanks for your valuable solution.

    I implemented the following function
    Qt Code:
    1. void MainWindow::dragEnterEvent(QDragEnterEvent *eve)
    2. {
    3. qDebug() << "Drag enter event";
    4. eve->accept();
    5.  
    6. }
    7. void MainWindow::dragMoveEvent(QDragMoveEvent *e)
    8. {
    9.  
    10. qDebug() << "Drag move event";
    11. e->accept();
    12. }
    13. bool MainWindow::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action)
    14. {
    15. QMessageBox::information(0,"",QString("Addu"));
    16. }
    To copy to clipboard, switch view to plain text mode 

    but complier is not going to dropMimeData function

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QDropEvent

    Because you still didn't bother to look into the docs. This time I will not give you a pointer but instead you're given a classic RTFM. I'll give you a hint though - you want to read about performing drag and drop with Item Views.
    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.


  11. #11
    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

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.