Skip to content

Commit 8e621f1

Browse files
Properly reparent TabWidget to DockWidget if TabWidget is removed from TabBar
1 parent 0948f73 commit 8e621f1

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

examples/simple/MainWindow.cpp

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
#include "ui_MainWindow.h"
44

55
#include <QLabel>
6+
#include <QTimer>
67

78
MainWindow::MainWindow(QWidget *parent) :
89
QMainWindow(parent),
910
ui(new Ui::MainWindow)
1011
{
11-
ui->setupUi(this);
12+
/*ui->setupUi(this);
1213
1314
// Create the dock manager. Because the parent parameter is a QMainWindow
1415
// the dock manager registers itself as the central widget.
@@ -31,7 +32,67 @@ MainWindow::MainWindow(QWidget *parent) :
3132
ui->menuView->addAction(DockWidget->toggleViewAction());
3233
3334
// Add the dock widget to the top dock widget area
34-
m_DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);
35+
m_DockManager->addDockWidget(ads::TopDockWidgetArea, DockWidget);*/
36+
37+
ui->setupUi(this);
38+
39+
// Create the dock manager. Because the parent parameter is a QMainWindow
40+
// the dock manager registers itself as the central widget.
41+
m_DockManager1 = new ads::CDockManager(this);
42+
43+
// Create example content label - this can be any application specific
44+
// widget
45+
ads::CDockWidget* DockWidget;
46+
{
47+
QLabel* l = new QLabel();
48+
l->setWordWrap(true);
49+
l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
50+
l->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ");
51+
52+
// Create a dock widget with the title Label 1 and set the created label
53+
// as the dock widget content
54+
DockWidget = new ads::CDockWidget("Label 1");
55+
DockWidget->setWidget(l);
56+
}
57+
58+
ads::CDockWidget* DockWidget2;
59+
{
60+
QLabel* l = new QLabel();
61+
l->setWordWrap(true);
62+
l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
63+
l->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ");
64+
65+
// Create a dock widget with the title Label 1 and set the created label
66+
// as the dock widget content
67+
DockWidget2 = new ads::CDockWidget("Label 2");
68+
DockWidget2->setWidget(l);
69+
}
70+
71+
72+
// Add the toggleViewAction of the dock widget to the menu to give
73+
// the user the possibility to show the dock widget if it has been closed
74+
ui->menuView->addAction(DockWidget->toggleViewAction());
75+
76+
// Add the dock widget to the top dock widget area
77+
m_DockManager1->addDockWidget(ads::TopDockWidgetArea, DockWidget);
78+
79+
80+
auto funcRemoveFirstManager = [=]()
81+
{
82+
m_DockManager1->removeDockWidget(DockWidget);
83+
84+
delete m_DockManager1;
85+
m_DockManager1 = nullptr;
86+
};
87+
QTimer::singleShot(3000, funcRemoveFirstManager);
88+
89+
auto funcAddSecondManager = [=]()
90+
{
91+
m_DockManager2 = new ads::CDockManager(this);
92+
93+
m_DockManager2->addDockWidget(ads::TopDockWidgetArea, DockWidget);
94+
};
95+
QTimer::singleShot(5000, funcAddSecondManager);
3596
}
3697

3798
MainWindow::~MainWindow()

examples/simple/MainWindow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class MainWindow : public QMainWindow
2020

2121
private:
2222
Ui::MainWindow *ui;
23-
ads::CDockManager* m_DockManager;
23+
ads::CDockManager* m_DockManager1;
24+
ads::CDockManager* m_DockManager2;
2425
};
2526

2627
#endif // MAINWINDOW_H

src/DockAreaWidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
453453
auto TabWidget = DockWidget->tabWidget();
454454
TabWidget->hide();
455455
d->tabBar()->removeTab(TabWidget);
456+
TabWidget->setParent(DockWidget);
456457
DockWidget->setDockArea(nullptr);
457458
CDockContainerWidget* DockContainer = dockContainer();
458459
if (NextOpenDockWidget)

0 commit comments

Comments
 (0)