mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-01-12 16:20:25 +08:00
Fixed takeWidget() function and fixed setWidget() function to handle case if there is already a content widget
This commit is contained in:
parent
9fe1dd6a88
commit
7a17aba42d
@ -169,7 +169,12 @@ static ads::CDockWidget* createCalendarDockWidget(QMenu* ViewMenu)
|
||||
static int CalendarCount = 0;
|
||||
QCalendarWidget* w = new QCalendarWidget();
|
||||
ads::CDockWidget* DockWidget = new ads::CDockWidget(QString("Calendar %1").arg(CalendarCount++));
|
||||
// The following lines are for testing the setWidget() and takeWidget()
|
||||
// functionality
|
||||
DockWidget->setWidget(w);
|
||||
DockWidget->setWidget(w); // what happens if we set a widget if a widget is already set
|
||||
DockWidget->takeWidget(); // we remove the widget
|
||||
DockWidget->setWidget(w); // and set the widget again - there should be no error
|
||||
DockWidget->setToggleViewActionMode(ads::CDockWidget::ActionModeShow);
|
||||
DockWidget->setIcon(svgIcon(":/adsdemo/images/date_range.svg"));
|
||||
ViewMenu->addAction(DockWidget->toggleViewAction());
|
||||
|
@ -257,6 +257,11 @@ void CDockWidget::setToggleViewActionChecked(bool Checked)
|
||||
//============================================================================
|
||||
void CDockWidget::setWidget(QWidget* widget, eInsertMode InsertMode)
|
||||
{
|
||||
if (d->Widget)
|
||||
{
|
||||
takeWidget();
|
||||
}
|
||||
|
||||
QScrollArea* ScrollAreaWidget = qobject_cast<QScrollArea*>(widget);
|
||||
if (ScrollAreaWidget || ForceNoScrollArea == InsertMode)
|
||||
{
|
||||
@ -280,10 +285,26 @@ void CDockWidget::setWidget(QWidget* widget, eInsertMode InsertMode)
|
||||
//============================================================================
|
||||
QWidget* CDockWidget::takeWidget()
|
||||
{
|
||||
d->ScrollArea->takeWidget();
|
||||
QWidget* w = nullptr;
|
||||
if (d->ScrollArea)
|
||||
{
|
||||
d->Layout->removeWidget(d->ScrollArea);
|
||||
w = d->ScrollArea->takeWidget();
|
||||
delete d->ScrollArea;
|
||||
d->ScrollArea = nullptr;
|
||||
}
|
||||
else if (d->Widget)
|
||||
{
|
||||
d->Layout->removeWidget(d->Widget);
|
||||
d->Widget->setParent(nullptr);
|
||||
return d->Widget;
|
||||
w = d->Widget;
|
||||
d->Widget = nullptr;
|
||||
}
|
||||
|
||||
if (w)
|
||||
{
|
||||
w->setParent(nullptr);
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user