From dae677e47983084a0572dbd571651f11dfe71b7d Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Tue, 10 Sep 2019 09:23:12 +0200 Subject: [PATCH] Added support for QToolButton tab close buttons --- src/DockManager.h | 1 + src/DockWidgetTab.cpp | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/DockManager.h b/src/DockManager.h index a75e76c..15a1641 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -129,6 +129,7 @@ public: OpaqueSplitterResize = 0x08, //!< See QSplitter::setOpaqueResize() documentation XmlAutoFormattingEnabled = 0x10,//!< If enabled, the XML writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace). XmlCompressionEnabled = 0x20,//!< If enabled, the XML output will be compressed and is not human readable anymore + TabCloseButtonIsToolButton = 0x40,//! If enabled the tab close buttons will be QToolButtons instead of QPushButtons - disabled by default DefaultConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton | OpaqueSplitterResize | XmlCompressionEnabled, ///< the default configuration }; Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag) diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index aaf4530..d4036e2 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -55,7 +55,6 @@ namespace ads { using tTabLabel = CElidingLabel; -using tCloseButton = QPushButton; /** * Private data class of CDockWidgetTab class (pimpl) @@ -72,7 +71,7 @@ struct DockWidgetTabPrivate eDragState DragState = DraggingInactive; CFloatingDockContainer* FloatingWidget = nullptr; QIcon Icon; - tCloseButton* CloseButton = nullptr; + QAbstractButton* CloseButton = nullptr; QSpacerItem* IconTextSpacer; /** @@ -122,6 +121,21 @@ struct DockWidgetTabPrivate { return DockArea->dockManager()->configFlags().testFlag(Flag); } + + /** + * Creates the close button as QPushButton or as QToolButton + */ + QAbstractButton* createCloseButton() const + { + if (testConfigFlag(CDockManager::TabCloseButtonIsToolButton)) + { + return new QToolButton(); + } + else + { + return new QPushButton(); + } + } }; // struct DockWidgetTabPrivate @@ -143,7 +157,7 @@ void DockWidgetTabPrivate::createLayout() TitleLabel->setObjectName("dockWidgetTabLabel"); TitleLabel->setAlignment(Qt::AlignCenter); - CloseButton = new tCloseButton(); + CloseButton = createCloseButton(); CloseButton->setObjectName("tabCloseButton"); // The standard icons do does not look good on high DPI screens QIcon CloseIcon; @@ -154,9 +168,9 @@ void DockWidgetTabPrivate::createLayout() CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); CloseButton->setVisible(false); - #ifndef QT_NO_TOOLTIP +#ifndef QT_NO_TOOLTIP CloseButton->setToolTip(QObject::tr("Close Tab")); - #endif +#endif _this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested())); QFontMetrics fm(TitleLabel->font());