PDA

View Full Version : Drag and drop from QPushButton



semajnosnibor
27th September 2010, 05:16
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):

void MagyAccent::e1Pressed()
{
ui->pbE1->setDown(true);
QDrag *drag = new QDrag(ui->pbE1);
QMimeData *mimeData = new QMimeData;
mimeData->setText(ui->pbA1->text());
drag->setMimeData(mimeData);
drag->exec();
ui->pbE1->setDown(false);
}

Thanks in advance!

semajnosnibor
27th September 2010, 22:43
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...

semajnosnibor
27th September 2010, 23:12
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)?

semajnosnibor
29th September 2010, 05:20
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.