Implementing drag and drop with QT 4.5 using QT Cr

2019-06-08 14:56发布

问题:

We're about to commit to Qt and C++ (sigh) to do some cross-platform development. The latest version of Qt 4.5 seems very nice as does the QT Creator IDE, which although simple compared to other IDEs, is a good way to get started.

I'm trying to understand how to do drag and drop into QT widgets from the "outside" world. As far as I can tell from the documentation, you're supposed to subclass a widget that you want to have respond to drop events and override some methods (the dragEnterEvent and dropEvent member functions) for that widget.

But if I use the Qt Creator tool, I don't seem to have any access to the classes of the widgets that I have created using the GUI form builder and so I can't subclass them.

WHat's the secret?

Thanks in advance, D

回答1:

Someone on my team figured it out ---- turns out there is an option to "Promote" a widget, meaning you can subclass it to something else and then override the needed methods with no pain.

Seems to me it would have been more obvious if it said "Subclass widget..." rather than "Promote" but that's OK.

This QT Creator is a very nice piece of work.



回答2:

I've never used QT creator environment, but I assume it spits out code afterward. Can you edit the code it spits out?

If you subclass the classes in a separate file, it shouldn't get overwritten when you rebuild your app with QT creator environment.

I suppose this is really a question for the QT creator forum though, sounds like a problem in THEIR user interface.