PDA

View Full Version : QDockWidget can't hear dragMoveEvent when undocked. Why?



pir
3rd February 2007, 16:48
Hi!
I have a QMainWindow that has a QDockWidget that shows a tree view. The tree view is supposed to let the user to rearange the tree by dragNdrop. This works fine when the program is started with the QDockWidget is attached to the QMainWindow. But when I have dettached the QDockWidget it only hears the startDrag(). But the dragMoveEvent is not triggered. If I reattach the QDockWidget to the QMainWindow again, it doesn't work either. It only works when the program is started with the QDockWidget attached to the QMainWindow.

I can't figure out why this is happening. Is there someone that has an idea?

wysota
3rd February 2007, 17:04
Which widget should handle the drag? The dock widget or the tree view?

pir
3rd February 2007, 17:13
The QDockWidget is only holding the treewidget. The mouse handling should be handled by the treewidget. I have tried to grab the mouse. But this did not work.

wysota
3rd February 2007, 18:44
Grab the mouse? What for? So if the problem concerns the tree drag, why do you ask about the dock widget? And is it a tree view or a tree widget?

pir
3rd February 2007, 19:49
Because I think that the problem is created by the QDockWidget. Everything worked when I used a QDialog. But I want to use a QDockWidget. And it works if the QDockWidget is attached to the QMainWindow and stop working when I have dettached it. That is why I am askint about the QDockWidget. Because I suppose that it doesn't receive the propper mouse actions it need to fullfill the dragndrop. That is why I thought that I maybe could try to grab the mouse. If I knew where the problem where, I wouldn't write this question... so the only thing I can do is to describe the problem.

It is a TreeView.

wysota
3rd February 2007, 21:03
Can we see a minimal compilable example reproducing the problem? And which exactly release of Qt do you use?

pir
3rd February 2007, 23:47
Sorry, the part of the program is too large. It would take me too long time prepare an example. I just wondered if it was a normal behaviour of QDockWidgets. I suppose it isn't.

I am using Qt-4.2.1

wysota
4th February 2007, 00:05
It would take me too long time prepare an example.
An example would help you make sure the error is not in your code.

I just wondered if it was a normal behaviour of QDockWidgets. I suppose it isn't.
It shouldn't be, but nobody says QDockWidget has to be responsible.

I couldn't find any entry in a task-tracker that'd seem related to the behaviour you experience.

Edit: I have written an example myself and it seems to work fine, so probably you have some error in your code.


#include <QMainWindow>
#include <QDockWidget>
#include <QApplication>
#include <QTreeWidget>


int main(int argc, char **argv){
QApplication app(argc, argv);
QMainWindow mw;
QDockWidget *dock = new QDockWidget(&mw);
QTreeWidget *tree = new QTreeWidget;
for(int i=0;i<5;i++)
(new QTreeWidgetItem(tree))->setText(0,QString::number(i+1));
tree->setDragDropMode(QAbstractItemView::DragDrop);
tree->setDragEnabled(true);
tree->setAcceptDrops(true);
dock->setWidget(tree);
mw.addDockWidget(Qt::LeftDockWidgetArea, dock);
mw.show();
return app.exec();
}

If I float the dock widget I can still drag and drop items in the tree. Qt version 4.2.2.

pir
4th February 2007, 01:42
I installed Qt-4.2.2 and now it works fine. Didn't need to change anything.

But thanks anyway