Widget dragging in MDI app
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?
================================
Code:
#include <QtGui>
{
public:
};
{
public:
setCentralWidget(workspace);
mdiChild *child = new mdiChild();
workspace->addWindow(child);
child->setGeometry(10,10,200,100);
child->show();
}
};
int main(int argc, char *argv[])
{
mainWindow mainWin;
mainWin.show();
return app.exec();
}
1 Attachment(s)
Re: Widget dragging in MDI app
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...
Re: Widget dragging in MDI app
Quote:
Originally Posted by
aamer4yu
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.
Re: Widget dragging in MDI app
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).