Dockable widgets: drag by body, not by header
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?
Re: Dockable widgets: drag by body, not by header
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.
Re: Dockable widgets: drag by body, not by header
Thanks for the reply,
eventually, I found the solution: remove unnecessary conditions from QDockWidgetPrivate class (mousePressEvent) and rebuild QtGui.
Code:
bool QDockWidgetPrivate
::mousePressEvent(QMouseEvent *event
) {
#if !defined(QT_NO_MAINWINDOW)
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.
Re: Dockable widgets: drag by body, not by header
Quote:
Originally Posted by
BigSmartFastAndrey
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.