Results 1 to 4 of 4

Thread: Drag and drop from QPushButton

  1. #1
    Join Date
    Sep 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Drag and drop from QPushButton

    I'm having some trouble with drag & dropping some text from a QPushButton. The drag and drop works correctly, where you click and hold down the left mouse button to drag the QPushButton text to an external document editor. The problem occurs after the drop, when you return the cursor to the application (the drag & drop source) any button or other widget the cursor moves over gets highlighted, but does not dehighlight once the mouse moves on to the next widget.
    I have done the drag & drop two different ways to try to solve it, one by subclassing the QPushButton, and the other by attaching a slot to the ButtonPressed signal from a standard QPushButton. Both produce the same result.
    I do know if you return to the application and click somewhere (anywhere but the button), the stuck highlighting stops. I tried faking a click programactically, but that didn't do anything.
    Am I missing something simple here to fix it, or do I have to just disable the hover highlighting?

    The drag code (everything else in the app is default):
    Qt Code:
    1. void MagyAccent::e1Pressed()
    2. {
    3. ui->pbE1->setDown(true);
    4. QDrag *drag = new QDrag(ui->pbE1);
    5. QMimeData *mimeData = new QMimeData;
    6. mimeData->setText(ui->pbA1->text());
    7. drag->setMimeData(mimeData);
    8. drag->exec();
    9. ui->pbE1->setDown(false);
    10. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance!

  2. #2
    Join Date
    Sep 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag and drop from QPushButton

    Further to my last post, this 'highlighting' problem only occurs when when the drop target is outside the application (which would be all cases), whether or not the drop was accepted. There must be a way to at the very least disable the highlighting...

  3. #3
    Join Date
    Sep 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag and drop from QPushButton

    Okay... ran some more tests on this, and I don't beleive it's anything to do with my choppy programming. I created a new project, added a QListWidget, and two QPushButtons, and set the following options on the listwidget: dragEnabled - true, dragDropMode - DragDrop. Aside from these nothing else was changed or added to the default 'skeleton' code.
    Now if you drag an item from the list and drop outside the application window (accepted or not) the highlighting issue should occur. So is this just an issue you have to live with for Qt (my version is 4.6.3)?

  4. #4
    Join Date
    Sep 2010
    Posts
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Drag and drop from QPushButton

    Well, further testing, compiled one of the examples from the help file (text tile dragger), and was able to replicate the button highlighting error (had to add a button to the UI). It seems that maybe it has to do with the fact that when you click to start a drag you get a ::mousePressEvent(), but if your drag ends outside the application, you do not get a corresponding ::mouseReleaseEvent(). Maybe a flag is waiting to be reset?
    Anyway tiring of all this I ended up just subclassing QLabel, adding drag & drop code and hover highlighting. It has the same problem, but a simple added function 'deHighlightOthers()' is called when ever a 'button' is to be highlighted. This solves the problem, however it would be tiresome to have to subclass other objects, such as checkboxes (which also have the highlighting issue).
    I guess the real question to ask would be, is this a problem with QT or is it an issue with how Winblows handles Drag 'n drops?
    Thanks for everyones help on this... wait I replied to my own thread.

Similar Threads

  1. Replies: 3
    Last Post: 10th June 2010, 15:13
  2. Replies: 0
    Last Post: 4th May 2010, 10:24
  3. Drag Drop Tab and more
    By BingoMaster in forum Newbie
    Replies: 1
    Last Post: 26th October 2009, 06:55
  4. drag and drop
    By nupul in forum Newbie
    Replies: 9
    Last Post: 8th April 2006, 22:51
  5. Drag and Drop (drop example)
    By din9 in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 18: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.