PDA

View Full Version : Implementing drag and drop for existing widget



dhjdhj
26th July 2010, 18:13
I think I'm missing something fundamental. I have been trying to make existing widgets like QListView, QLineEdit accept drops from external applications. The documentation suggests that one needs to reimplement virtual methods such as DropEvent. I have certainly been able to do this by subclassing QLineEdit to MyLineEdit (for example) with no problem.

However, there are properties such as "acceptDrops" defined for these widgets that would seem to suggest that it is possible to drop items into widgets without having to subclass them, simply adding code to the MainWindow class, for example. However, I have not been able to find any way to do this, I don't see any signals available to which I could connect and so forth.

All the examples I have found do indeed subclass the widget. So what am I missing?

Thanks,
D

franz
26th July 2010, 18:28
Have a look at the QWidget documentation, especially the part about the acceptDrops property. It should give you something to work with.

dhjdhj
26th July 2010, 18:39
Appreciate the response. I saw all that before I posted .... it wasn't particularly informative. If you have a pointer to an actual example where a widget like QLineEdit dropped into a layout inside a MainWindow in QtCreator can be made to respond to drops without subclassing, I'd love to see it.

franz
26th July 2010, 19:32
I don't have the possibility to test atm, but it is very likely that if you setAcceptDrops(true); then QLineEdit should accept them and display anything that is reasonably convertible to QString.

dhjdhj
27th July 2010, 01:13
That may be but how is the application notified that a drop has happened? I don't want to poll the widget.

franz
27th July 2010, 06:04
Look for the textChanged(), textEdited() and editingFinished() signals that QLineEdit has.