This commit is contained in:
Uwe Kindler 2020-08-17 23:51:14 +02:00
commit f72a8568c5
8 changed files with 124 additions and 16 deletions

View File

@ -202,6 +202,9 @@ class MainWindow(MainWindowUI, MainWindowBase):
# Test custom factory - we inject a help button into the title bar
QtAds.CDockComponentsFactory.setFactory(CCustomComponentsFactory())
top_dock_area = self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, file_system_widget)
# Uncomment the next line if you would like to test the
# setHideSingleWidgetTitleBar() functionality
# top_dock_area.setHideSingleWidgetTitleBar(True)
QtAds.CDockComponentsFactory.resetDefaultFactory()
# We create a calendar widget and clear all flags to prevent the dock area
@ -310,6 +313,7 @@ class MainWindow(MainWindowUI, MainWindowBase):
def closeEvent(self, event: QCloseEvent):
self.save_state()
self.dock_manager.deleteLater()
super().closeEvent(event)
def on_actionSaveState_triggered(self, state: bool):

View File

@ -0,0 +1,73 @@
import sys
from PyQtAds import QtAds
from PyQt5.QtGui import QCloseEvent
from PyQt5.QtCore import (qDebug, pyqtSlot, QObject, pyqtSignal)
from PyQt5.QtWidgets import (QMainWindow, QAction, QTextEdit, QApplication,
QMenuBar)
class MainWindow(QMainWindow):
dock_manager = None
def closeEvent(self, event: QCloseEvent):
super().closeEvent(event)
if self.dock_manager is not None:
self.dock_manager.deleteLater()
def setDockManager(self, dock_manager: QtAds.CDockManager):
self.dock_manager = dock_manager
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MainWindow()
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.FocusHighlighting, True)
QtAds.CDockManager.setConfigFlag(QtAds.CDockManager.AllTabsHaveCloseButton, True)
dock_manager = QtAds.CDockManager(w)
w.setDockManager(dock_manager)
count = 0
def on_focused_dock_widget_changed(old: QtAds.CDockWidget, now: QtAds.CDockWidget):
global count
qDebug( "{:d} CDockManager::focusedDockWidgetChanged old: {} now: {} visible: {}".format(
count,
old.objectName() if old else "-",
now.objectName(),
now.isVisible()))
count += 1
now.widget().setFocus()
dock_manager.focusedDockWidgetChanged.connect(on_focused_dock_widget_changed)
action = QAction("New Delete On Close", w)
w.menuBar().addAction(action)
i = 0
def on_action_triggered():
global i
dw = QtAds.CDockWidget("test doc {:d}".format(i))
i += 1
editor = QTextEdit("lorem ipsum...", dw)
dw.setWidget(editor)
dw.setFeature(QtAds.CDockWidget.DockWidgetDeleteOnClose, True)
area = dock_manager.addDockWidgetTab(QtAds.CenterDockWidgetArea, dw)
qDebug("doc dock widget created! {} {}".format(dw, area))
action.triggered.connect(on_action_triggered)
action = QAction("New", w)
w.menuBar().addAction(action)
def on_action2_triggered():
global i
dw = QtAds.CDockWidget("test {:d}".format(i))
i += 1
editor = QTextEdit("lorem ipsum...", dw)
dw.setWidget(editor)
area = dock_manager.addDockWidgetTab(QtAds.CenterDockWidgetArea, dw)
qDebug("dock widget created! {} {}".format(dw, area))
action.triggered.connect(on_action2_triggered)
w.show()
app.exec_()

View File

@ -2,7 +2,8 @@ import os
import sys
from PyQt5 import uic
from PyQt5.QtCore import Qt
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtGui import QCloseEvent
from PyQt5.QtWidgets import QApplication, QLabel
from PyQtAds import QtAds
@ -20,7 +21,7 @@ class MainWindow(MainWindowUI, MainWindowBase):
# Create the dock manager. Because the parent parameter is a QMainWindow
# the dock manager registers itself as the central widget.
self.dock_manager = QtAds.CDockManager(self)
self.dock_manager1 = QtAds.CDockManager(self)
# Create example content label - this can be any application specific
# widget
@ -34,12 +35,41 @@ class MainWindow(MainWindowUI, MainWindowBase):
dock_widget = QtAds.CDockWidget("Label 1")
dock_widget.setWidget(l)
l = QLabel()
l.setWordWrap(True)
l.setAlignment(Qt.AlignTop | Qt.AlignLeft);
l.setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ")
# Create a dock widget with the title Label 1 and set the created label
# as the dock widget content
dock_widget2 = QtAds.CDockWidget("Label 2")
dock_widget2.setWidget(l)
# Add the toggleViewAction of the dock widget to the menu to give
# the user the possibility to show the dock widget if it has been closed
self.menuView.addAction(dock_widget.toggleViewAction())
# Add the dock widget to the top dock widget area
self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, dock_widget)
self.dock_manager1.addDockWidget(QtAds.TopDockWidgetArea, dock_widget)
def remove_first_manager():
self.dock_manager1.removeDockWidget(dock_widget)
del self.dock_manager1
QTimer.singleShot(3000, remove_first_manager)
def add_second_manager():
self.dock_manager2 = QtAds.CDockManager(self)
self.dock_manager2.addDockWidget(QtAds.TopDockWidgetArea, dock_widget)
QTimer.singleShot(5000, add_second_manager)
def closeEvent(self, event: QCloseEvent):
super().closeEvent(event)
if hasattr(self, 'dock_manager1'):
self.dock_manager1.deleteLater()
if hasattr(self, 'dock_manager2'):
self.dock_manager2.deleteLater()
if __name__ == '__main__':

View File

@ -51,6 +51,7 @@ public:
void setAllowedAreas(DockWidgetAreas areas);
DockWidgetAreas allowedAreas() const;
void setHideSingleWidgetTitleBar(bool hide);
CDockAreaTitleBar* titleBar() const;
public slots:

View File

@ -224,11 +224,11 @@ signals:
void stateRestored();
void openingPerspective(const QString& PerspectiveName);
void perspectiveOpened(const QString& PerspectiveName);
void floatingWidgetCreated(CFloatingDockContainer* FloatingWidget);
void dockAreaCreated(ads::CDockAreaWidget* DockArea);
void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);
void dockWidgetRemoved(ads::CDockWidget* DockWidget);
void focusedDockWidgetChanged(ads::CDockWidget* old, ads::CDockWidget* now);
void floatingWidgetCreated(ads::CFloatingDockContainer*);
void dockAreaCreated(ads::CDockAreaWidget*);
void dockWidgetAboutToBeRemoved(ads::CDockWidget*);
void dockWidgetRemoved(ads::CDockWidget*);
void focusedDockWidgetChanged(ads::CDockWidget*, ads::CDockWidget*);
};
};

View File

@ -276,7 +276,7 @@ signals:
* This signal is emitted if a dock area is opened or closed via
* toggleView() function
*/
void dockAreaViewToggled(CDockAreaWidget* DockArea, bool Open);
void dockAreaViewToggled(ads::CDockAreaWidget* DockArea, bool Open);
}; // class DockContainerWidget
} // namespace ads
//-----------------------------------------------------------------------------

View File

@ -502,20 +502,20 @@ signals:
* An application can use this signal to e.g. subscribe to events of
* the newly created window.
*/
void floatingWidgetCreated(CFloatingDockContainer* FloatingWidget);
void floatingWidgetCreated(ads::CFloatingDockContainer* FloatingWidget);
/**
* This signal is emitted, if a new DockArea has been created.
* An application can use this signal to set custom icons or custom
* tooltips for the DockArea buttons.
*/
void dockAreaCreated(CDockAreaWidget* DockArea);
void dockAreaCreated(ads::CDockAreaWidget* DockArea);
/**
* This signal is emitted just before the given dock widget is removed
* from the
*/
void dockWidgetAboutToBeRemoved(CDockWidget* DockWidget);
void dockWidgetAboutToBeRemoved(ads::CDockWidget* DockWidget);
/**
* This signal is emitted if a dock widget has been removed with the remove
@ -523,14 +523,14 @@ signals:
* If this signal is emitted, the dock widget has been removed from the
* docking system but it is not deleted yet.
*/
void dockWidgetRemoved(CDockWidget* DockWidget);
void dockWidgetRemoved(ads::CDockWidget* DockWidget);
/**
* This signal is emitted if the focused dock widget changed.
* Both old and now can be nullptr.
* The focused dock widget is the one that is highlighted in the GUI
*/
void focusedDockWidgetChanged(CDockWidget* old, CDockWidget* now);
void focusedDockWidgetChanged(ads::CDockWidget* old, ads::CDockWidget* now);
}; // class DockManager
} // namespace ads
//-----------------------------------------------------------------------------

View File

@ -577,7 +577,7 @@ signals:
* This signal is emitted when the features property changes.
* The features parameter gives the new value of the property.
*/
void featuresChanged(DockWidgetFeatures features);
void featuresChanged(ads::CDockWidget::DockWidgetFeatures features);
}; // class DockWidget
}
// namespace ads