PDA

View Full Version : Top level widgets shown while moving dockwidgets



harregui
15th March 2011, 11:15
Hi all,
I wonder how I can show 4 static widgets (arrows) that are top level in the MainWindow, while I'm moving QDockWidgets.

I've tried Qt::Popup flag, but that makes the last added widget to receive all the events and I miss the correct dockwidget movement. I can make myCustomControl to work (it shows information about dockPositions), but the default movement of the dockwidget drag doesn't work.

Any idea? Should I use another flag, or how to send the events to my MainWindow? This is my eventFilter (it works when widgets don't use the Qt::Popup flag):



bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(obj->inherits("QDockWidget"))
{
if(event->type() == QEvent::Paint)
{
return QMainWindow::eventFilter(obj, event);
}

qDebug() << "QDockWidget event received";
QDockWidget *dockwidget = static_cast<QDockWidget*>(obj);
dockwidget->setAllowedAreas(Qt::NoDockWidgetArea); /*This avoids drawing the blue target gap*/

if (event->type() == QEvent::MouseButtonPress)
{
qDebug () << "Mouse Button Press in dockwidget received";
mousePressed = true;
dockDragging = dockwidget;
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
dragStartPosition = mouseEvent->pos();
return QMainWindow::eventFilter(obj, event);
}
if (event->type() == QEvent::MouseMove)
{
qDebug () << "Mouse Move in dockwidget received";
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if(mousePressed && (mouseEvent->pos() - dragStartPosition).manhattanLength() > QApplication::startDragDistance())
{
trackDockWidgetsPositions(Qt::AllDockWidgetAreas);
if(arrows->areHidden())
{
showMainArrows();
qDebug () << "Arrows shown" ;
}
myCustomControl();
}

return QMainWindow::eventFilter(obj, event);
}
if (event->type() == QEvent::MouseButtonRelease)
{
qDebug () << "Mouse Button Release in dockwidget received";
hideMainArrows();
mousePressed = false;
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
positionControl(mouseEvent->globalPos(), dockwidget);
if(dockwidget->isHidden())
{
dockwidget->show();
}
return QMainWindow::eventFilter(obj, event);
}

}

if(obj->inherits("ControlArrow"))
{
qDebug() << "event" << event->type();
if(event->type() == QEvent::Paint)
{
return QMainWindow::eventFilter(obj, event);
}
else if(event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
return DragDropControl::eventFilter(dockDragging, event);
}
}
return QMainWindow::eventFilter(obj, event);
}

harregui
15th March 2011, 16:26
Qt::ToolTip