Added spacer widget to handle mouse events properly in CDockAreaTitleBar, added missing updateGeometry calls to CDockAreaTabBar

This commit is contained in:
Uwe Kindler 2020-02-07 22:49:10 +01:00
parent c4872c6b10
commit 8113bf63ba
2 changed files with 33 additions and 4 deletions

View File

@ -445,9 +445,15 @@ bool CDockAreaTabBar::eventFilter(QObject *watched, QEvent *event)
switch (event->type())
{
case QEvent::Hide:
emit tabClosed(d->TabsLayout->indexOf(Tab)); break;
emit tabClosed(d->TabsLayout->indexOf(Tab));
updateGeometry();
break;
case QEvent::Show:
emit tabOpened(d->TabsLayout->indexOf(Tab)); break;
emit tabOpened(d->TabsLayout->indexOf(Tab));
updateGeometry();
break;
default:
break;
}

View File

@ -185,6 +185,30 @@ protected:
};
/**
* This spacer widget is here because of the following problem.
* The dock area title bar handles mouse dragging and moving the floating widget.
* The problem is, that if the title bar becomes invisible, i.e. if the dock
* area contains only one single dock widget and the dock area is moved
* into a floating widget, then mouse events are not handled anymore and dragging
* of the floating widget stops.
*/
class CSpacerWidget : public QWidget
{
Q_OBJECT
public:
using Super = QWidget;
CSpacerWidget(QWidget* Parent = 0)
: Super(Parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setStyleSheet("border: none; background: none;");
}
virtual QSize sizeHint() const override {return QSize(0, 0);}
virtual QSize minimumSizeHint() const override {return QSize(0, 0);}
};
//============================================================================
DockAreaTitleBarPrivate::DockAreaTitleBarPrivate(CDockAreaTitleBar* _public) :
_this(_public)
@ -322,8 +346,7 @@ CDockAreaTitleBar::CDockAreaTitleBar(CDockAreaWidget* parent) :
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
d->createTabBar();
auto horizontalSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
d->Layout->addSpacerItem(horizontalSpacer);
d->Layout->addWidget(new CSpacerWidget(this));
d->createButtons();
}