Fixed CustomCloseHandling for floating widgets

This commit is contained in:
Uwe Kindler 2022-07-29 13:25:14 +02:00
parent df74686287
commit a0f0640c9f
2 changed files with 26 additions and 2 deletions

View File

@ -458,7 +458,21 @@ void MainWindowPrivate::createContent()
DockManager->addDockWidget(ads::TopDockWidgetArea, createLongTextLabelDockWidget(), RighDockArea);
auto BottomDockArea = DockManager->addDockWidget(ads::BottomDockWidgetArea, createLongTextLabelDockWidget(), RighDockArea);
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(), RighDockArea);
DockManager->addDockWidget(ads::CenterDockWidgetArea, createLongTextLabelDockWidget(), BottomDockArea);
auto LabelDockWidget = createLongTextLabelDockWidget();
std::cout << "DockWidget " << LabelDockWidget->objectName().toStdString() << std::endl;
DockManager->addDockWidget(ads::CenterDockWidgetArea, LabelDockWidget, BottomDockArea);
// Tests CustomCloseHandling without DeleteOnClose
LabelDockWidget->setFeature(ads::CDockWidget::CustomCloseHandling, true);
QObject::connect(LabelDockWidget, &ads::CDockWidget::closeRequested, [LabelDockWidget, this]()
{
int Result = QMessageBox::question(_this, "Custom Close Request",
"Do you really want to close this dock widget?");
if (QMessageBox::Yes == Result)
{
LabelDockWidget->closeDockWidget();
}
});
Action = ui.menuTests->addAction(QString("Set %1 Floating").arg(DockWidget->windowTitle()));
DockWidget->connect(Action, SIGNAL(triggered()), SLOT(setFloating()));

View File

@ -807,11 +807,16 @@ void CFloatingDockContainer::closeEvent(QCloseEvent *event)
return;
}
bool HasOpenDockWidgets = false;
for (auto DockWidget : d->DockContainer->openedDockWidgets())
{
if (DockWidget->features().testFlag(CDockWidget::DockWidgetDeleteOnClose) || DockWidget->features().testFlag(CDockWidget::CustomCloseHandling))
{
DockWidget->closeDockWidgetInternal();
bool Closed = DockWidget->closeDockWidgetInternal();
if (!Closed)
{
HasOpenDockWidgets = true;
}
}
else
{
@ -819,6 +824,11 @@ void CFloatingDockContainer::closeEvent(QCloseEvent *event)
}
}
if (HasOpenDockWidgets)
{
return;
}
// In Qt version after 5.9.2 there seems to be a bug that causes the
// QWidget::event() function to not receive any NonClientArea mouse
// events anymore after a close/show cycle. The bug is reported here: