PDA

View Full Version : Widget dragging in MDI app



zeeeend
16th January 2007, 21:58
Funny behaviour of child widgets in MDI apps.

MDI child widgets (unless you use editable widgets like QTextedit) are dragged in QWorkspace when you move the mouse with pressed left mouse button anywhere inside the widget. This prohibits drawing/measuring with the mouse inside the widget.

Source code below compiles to what I mean.

The MDI example in Qt examples/mainwindows has the same behaviour when the MDI child widget inherits QWidget instead of QTextEdit in the example.
I use Qt 4.2.2. The problem is the same with Linux and Windows.

Any suggestions to overcome this? Feels like a bug, but maybe it`s defined behaviour, and I should just change a windowsFlag somewhere?

================================

#include <QtGui>
class mdiChild:public QWidget
{
public:
mdiChild():QWidget(){}
};

class mainWindow:public QMainWindow
{
public:
mainWindow():QMainWindow() {
QWorkspace* workspace = new QWorkspace;
setCentralWidget(workspace);

mdiChild *child = new mdiChild();
workspace->addWindow(child);
child->setGeometry(10,10,200,100);
child->show();
}
};

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
mainWindow mainWin;
mainWin.show();
return app.exec();
}

aamer4yu
17th January 2007, 04:33
Moving the widget seems to be the default behaviour of the widget.
To draw on the widget implement the mousepress, mousemove and mouse release events... and override the paintevent to draw inside the widget...


check the code attached...

zeeeend
17th January 2007, 20:36
Moving the widget seems to be the default behaviour of the widget.
To draw on the widget implement the mousepress, mousemove and mouse release events... and override the paintevent to draw inside the widget...

Yes, that sure a way to prevent the widget from moving, thanks.
But I don` understand why default widget behaviour in QWorkspace is different from standard behaviour.
For widgets like QStatusBar inside a MdiChild it is a bit freaky, to reimplement QStatusBar and override mouse events, just to prevent the MdiChild from accidently moving.

wysota
17th January 2007, 21:11
If I understand the concept correctly, then you only need to reimplement those events for direct children of the workspace, so if you don't use floating QStatusBar widgets, you won't need to touch them. Anyway I think that's not needed as well, as you can probably do everything by reimplementing mouse events in QWorkspace (there probably is an event filter installed somewhere, so even that might not be necessary).