PDA

View Full Version : Dockable widgets: drag by body, not by header



BigSmartFastAndrey
27th March 2012, 05:57
Hello all.

I have this problem today. I want to drag QDockWidget objects inside QMainWindow catching them by body, but no by header. There are no dock widgets headers in application I written.

I tried to solve this problem putting body widget in the header entirely. But docking behaviour was really bad in this case...

Does anyone know the solution?

wysota
27th March 2012, 20:59
It should be possible to do what you want by intercepting mouse events and translating them so that the widget thinks it is dragged by the header.

BigSmartFastAndrey
28th March 2012, 05:17
Thanks for the reply,
eventually, I found the solution: remove unnecessary conditions from QDockWidgetPrivate class (mousePressEvent) and rebuild QtGui.


bool QDockWidgetPrivate::mousePressEvent(QMouseEvent *event)
{
#if !defined(QT_NO_MAINWINDOW)
Q_Q(QDockWidget);

QDockWidgetLayout *dwLayout
= qobject_cast<QDockWidgetLayout*>(layout);

if (!dwLayout->nativeWindowDeco()) {
QRect titleArea = dwLayout->titleArea();

if (event->button() != Qt::LeftButton ||
!titleArea.contains(event->pos()) ||
// check if the tool window is movable... do nothing if it
// is not (but allow moving if the window is floating)
(!hasFeature(this, QDockWidget::DockWidgetMovable) && !q->isFloating()) ||
qobject_cast<QMainWindow*>(parent) == 0 ||
isAnimating() || state != 0) {
return false;
}

initDrag(event->pos(), false);

if (state)
state->ctrlDrag = hasFeature(this, QDockWidget::DockWidgetFloatable) && event->modifiers() & Qt::ControlModifier;

return true;
}

#endif // !defined(QT_NO_MAINWINDOW)
return false;
}

Line number 13 above.

wysota
28th March 2012, 08:43
Thanks for the reply,
eventually, I found the solution: remove unnecessary conditions from QDockWidgetPrivate class (mousePressEvent) and rebuild QtGui.
That's not really a solution unless you intend to break all programs using Qt on your system and some programs of everyone's using your application.