You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, September 20th 2012, 1:54pm

Drag and Drop outside the Main Window

Hi, I have a question about the drag and drop.

I created a custom widget that inherits from QWidget. This custom widget can be located in 2 different places. Initially, the custom widget is located in a QTabWidget (in fact a class that inherits from QTabWidget). This QTabWidget is located into a QDockedWidget in QMainWindow.

I want to be able to drag the tab containing the custom widget, and create a top level window. So, when the main window will be minimized, my custom widget will not. Finally, I want to be able to put back the top level window in the QTabWidget.

So far, I have created a class (CustomTabBar) that inherits from QTabBar, in order to be able to drag the custom widget from the QTabWidget to the outside (I'm using Qt 4.4.3 in CentOS 4). I reimplemented the mousePressEvent and mouseMoveEvent functions. In the mouseMoveEvent function, if the moving distance is long enough, I created a QDrag object.

First problem : I cannot drop outside QMainWindow. Is there a way to do this? Should I use a particular mime data?

So, now, I'm not able to drop outside QMainWindow, but I can inside it, since I added some code to be able to do it and accept drops. My custom widget is now independant from QMainWindow (I have set his parent to NULL), and I can minimize QMainWindow without affecting my custom widget.

Now, I want to put back my custom widget into the QTabWidget. So I have reimplemented dragEnterEvent and dropEvent functions in my CustomTabBar and in the QTabWidget, and set them to accept drops. But when I begin the drag, my cursor doesn't change to tell me a drag has begins, and thus the QTabWidget does not accept the drop. So I tried to initialize the drag from my custom widget, ie detect the mouse press and move events, but these are not even called.

Second problem: How do I initialize the drag from my custom widget (now a top level window)?

Thanks

Similar threads

Used tags

Drag and Drop