Skip to content

Commit f72a856

Browse files
2 parents 11aec65 + 7584141 commit f72a856

File tree

8 files changed

+124
-16
lines changed

8 files changed

+124
-16
lines changed

demo/demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ def create_content(self):
202202
# Test custom factory - we inject a help button into the title bar
203203
QtAds.CDockComponentsFactory.setFactory(CCustomComponentsFactory())
204204
top_dock_area = self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, file_system_widget)
205+
# Uncomment the next line if you would like to test the
206+
# setHideSingleWidgetTitleBar() functionality
207+
# top_dock_area.setHideSingleWidgetTitleBar(True)
205208
QtAds.CDockComponentsFactory.resetDefaultFactory()
206209

207210
# We create a calendar widget and clear all flags to prevent the dock area
@@ -310,6 +313,7 @@ def create_actions(self):
310313

311314
def closeEvent(self, event: QCloseEvent):
312315
self.save_state()
316+
self.dock_manager.deleteLater()
313317
super().closeEvent(event)
314318

315319
def on_actionSaveState_triggered(self, state: bool):
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import sys
2+
3+
from PyQtAds import QtAds
4+
from PyQt5.QtGui import QCloseEvent
5+
from PyQt5.QtCore import (qDebug, pyqtSlot, QObject, pyqtSignal)
6+
from PyQt5.QtWidgets import (QMainWindow, QAction, QTextEdit, QApplication,
7+
QMenuBar)
8+
9+
10+
class MainWindow(QMainWindow):
11+
dock_manager = None
12+
13+
def closeEvent(self, event: QCloseEvent):
14+
super().closeEvent(event)
15+
if self.dock_manager is not None:
16+
self.dock_manager.deleteLater()
17+
18+
def setDockManager(self, dock_manager: QtAds.CDockManager):
19+
self.dock_manager = dock_manager
20+
21+
22+
if __name__ == '__main__':
23+
app = QApplication(sys.argv)
24+
w = MainWindow()
25+
26+
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.FocusHighlighting, True)
27+
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.AllTabsHaveCloseButton, True)
28+
dock_manager = QtAds.CDockManager(w)
29+
w.setDockManager(dock_manager)
30+
31+
count = 0
32+
33+
def on_focused_dock_widget_changed(old: QtAds.CDockWidget, now: QtAds.CDockWidget):
34+
global count
35+
qDebug( "{:d} CDockManager::focusedDockWidgetChanged old: {} now: {} visible: {}".format(
36+
count,
37+
old.objectName() if old else "-",
38+
now.objectName(),
39+
now.isVisible()))
40+
count += 1
41+
now.widget().setFocus()
42+
43+
dock_manager.focusedDockWidgetChanged.connect(on_focused_dock_widget_changed)
44+
45+
action = QAction("New Delete On Close", w)
46+
w.menuBar().addAction(action)
47+
48+
i = 0
49+
def on_action_triggered():
50+
global i
51+
dw = QtAds.CDockWidget("test doc {:d}".format(i))
52+
i += 1
53+
editor = QTextEdit("lorem ipsum...", dw)
54+
dw.setWidget(editor)
55+
dw.setFeature(QtAds.CDockWidget.DockWidgetDeleteOnClose, True)
56+
area = dock_manager.addDockWidgetTab(QtAds.CenterDockWidgetArea, dw)
57+
qDebug("doc dock widget created! {} {}".format(dw, area))
58+
action.triggered.connect(on_action_triggered)
59+
60+
action = QAction("New", w)
61+
w.menuBar().addAction(action)
62+
def on_action2_triggered():
63+
global i
64+
dw = QtAds.CDockWidget("test {:d}".format(i))
65+
i += 1
66+
editor = QTextEdit("lorem ipsum...", dw)
67+
dw.setWidget(editor)
68+
area = dock_manager.addDockWidgetTab(QtAds.CenterDockWidgetArea, dw)
69+
qDebug("dock widget created! {} {}".format(dw, area))
70+
action.triggered.connect(on_action2_triggered)
71+
72+
w.show()
73+
app.exec_()

examples/simple/simple.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import sys
33

44
from PyQt5 import uic
5-
from PyQt5.QtCore import Qt
5+
from PyQt5.QtCore import Qt, QTimer
6+
from PyQt5.QtGui import QCloseEvent
67
from PyQt5.QtWidgets import QApplication, QLabel
78

89
from PyQtAds import QtAds
@@ -20,7 +21,7 @@ def __init__(self, parent=None):
2021

2122
# Create the dock manager. Because the parent parameter is a QMainWindow
2223
# the dock manager registers itself as the central widget.
23-
self.dock_manager = QtAds.CDockManager(self)
24+
self.dock_manager1 = QtAds.CDockManager(self)
2425

2526
# Create example content label - this can be any application specific
2627
# widget
@@ -33,13 +34,42 @@ def __init__(self, parent=None):
3334
# as the dock widget content
3435
dock_widget = QtAds.CDockWidget("Label 1")
3536
dock_widget.setWidget(l)
37+
38+
l = QLabel()
39+
l.setWordWrap(True)
40+
l.setAlignment(Qt.AlignTop | Qt.AlignLeft);
41+
l.setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ")
42+
43+
# Create a dock widget with the title Label 1 and set the created label
44+
# as the dock widget content
45+
dock_widget2 = QtAds.CDockWidget("Label 2")
46+
dock_widget2.setWidget(l)
3647

3748
# Add the toggleViewAction of the dock widget to the menu to give
3849
# the user the possibility to show the dock widget if it has been closed
3950
self.menuView.addAction(dock_widget.toggleViewAction())
4051

4152
# Add the dock widget to the top dock widget area
42-
self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, dock_widget)
53+
self.dock_manager1.addDockWidget(QtAds.TopDockWidgetArea, dock_widget)
54+
55+
def remove_first_manager():
56+
self.dock_manager1.removeDockWidget(dock_widget)
57+
del self.dock_manager1
58+
QTimer.singleShot(3000, remove_first_manager)
59+
60+
def add_second_manager():
61+
self.dock_manager2 = QtAds.CDockManager(self)
62+
self.dock_manager2.addDockWidget(QtAds.TopDockWidgetArea, dock_widget)
63+
QTimer.singleShot(5000, add_second_manager)
64+
65+
def closeEvent(self, event: QCloseEvent):
66+
super().closeEvent(event)
67+
68+
if hasattr(self, 'dock_manager1'):
69+
self.dock_manager1.deleteLater()
70+
71+
if hasattr(self, 'dock_manager2'):
72+
self.dock_manager2.deleteLater()
4373

4474

4575
if __name__ == '__main__':

sip/DockAreaWidget.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public:
5151

5252
void setAllowedAreas(DockWidgetAreas areas);
5353
DockWidgetAreas allowedAreas() const;
54+
void setHideSingleWidgetTitleBar(bool hide);
5455
CDockAreaTitleBar* titleBar() const;
5556

5657
public slots:

sip/DockManager.sip

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%Import QtWidgets/QtWidgetsmod.sip
22

33
%If (Qt_5_0_0 -)
4-
4+
55
%MappedType QMap<QString, ads::CDockWidget*>
66
/TypeHint="Dict[QString, CDockWidget*]", TypeHintValue="{}"/
77
{
@@ -224,11 +224,11 @@ signals:
224224
void stateRestored();
225225
void openingPerspective(const QString& PerspectiveName);
226226
void perspectiveOpened(const QString& PerspectiveName);
227-
void floatingWidgetCreated(CFloatingDockContainer* FloatingWidget);
228-
void dockAreaCreated(ads::CDockAreaWidget* DockArea);
229-
void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);
230-
void dockWidgetRemoved(ads::CDockWidget* DockWidget);
231-
void focusedDockWidgetChanged(ads::CDockWidget* old, ads::CDockWidget* now);
227+
void floatingWidgetCreated(ads::CFloatingDockContainer*);
228+
void dockAreaCreated(ads::CDockAreaWidget*);
229+
void dockWidgetAboutToBeRemoved(ads::CDockWidget*);
230+
void dockWidgetRemoved(ads::CDockWidget*);
231+
void focusedDockWidgetChanged(ads::CDockWidget*, ads::CDockWidget*);
232232
};
233233

234234
};

src/DockContainerWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
276276
* This signal is emitted if a dock area is opened or closed via
277277
* toggleView() function
278278
*/
279-
void dockAreaViewToggled(CDockAreaWidget* DockArea, bool Open);
279+
void dockAreaViewToggled(ads::CDockAreaWidget* DockArea, bool Open);
280280
}; // class DockContainerWidget
281281
} // namespace ads
282282
//-----------------------------------------------------------------------------

src/DockManager.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,35 +502,35 @@ public slots:
502502
* An application can use this signal to e.g. subscribe to events of
503503
* the newly created window.
504504
*/
505-
void floatingWidgetCreated(CFloatingDockContainer* FloatingWidget);
505+
void floatingWidgetCreated(ads::CFloatingDockContainer* FloatingWidget);
506506

507507
/**
508508
* This signal is emitted, if a new DockArea has been created.
509509
* An application can use this signal to set custom icons or custom
510510
* tooltips for the DockArea buttons.
511511
*/
512-
void dockAreaCreated(CDockAreaWidget* DockArea);
512+
void dockAreaCreated(ads::CDockAreaWidget* DockArea);
513513

514514
/**
515515
* This signal is emitted just before the given dock widget is removed
516516
* from the
517517
*/
518-
void dockWidgetAboutToBeRemoved(CDockWidget* DockWidget);
518+
void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);
519519

520520
/**
521521
* This signal is emitted if a dock widget has been removed with the remove
522522
* removeDockWidget() function.
523523
* If this signal is emitted, the dock widget has been removed from the
524524
* docking system but it is not deleted yet.
525525
*/
526-
void dockWidgetRemoved(CDockWidget* DockWidget);
526+
void dockWidgetRemoved(ads::CDockWidget* DockWidget);
527527

528528
/**
529529
* This signal is emitted if the focused dock widget changed.
530530
* Both old and now can be nullptr.
531531
* The focused dock widget is the one that is highlighted in the GUI
532532
*/
533-
void focusedDockWidgetChanged(CDockWidget* old, CDockWidget* now);
533+
void focusedDockWidgetChanged(ads::CDockWidget* old, ads::CDockWidget* now);
534534
}; // class DockManager
535535
} // namespace ads
536536
//-----------------------------------------------------------------------------

src/DockWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ public slots:
577577
* This signal is emitted when the features property changes.
578578
* The features parameter gives the new value of the property.
579579
*/
580-
void featuresChanged(DockWidgetFeatures features);
580+
void featuresChanged(ads::CDockWidget::DockWidgetFeatures features);
581581
}; // class DockWidget
582582
}
583583
// namespace ads

0 commit comments

Comments
 (0)