Skip to content

Commit dae677e

Browse files
Added support for QToolButton tab close buttons
1 parent a05078c commit dae677e

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/DockManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
129129
OpaqueSplitterResize = 0x08, //!< See QSplitter::setOpaqueResize() documentation
130130
XmlAutoFormattingEnabled = 0x10,//!< If enabled, the XML writer automatically adds line-breaks and indentation to empty sections between elements (ignorable whitespace).
131131
XmlCompressionEnabled = 0x20,//!< If enabled, the XML output will be compressed and is not human readable anymore
132+
TabCloseButtonIsToolButton = 0x40,//! If enabled the tab close buttons will be QToolButtons instead of QPushButtons - disabled by default
132133
DefaultConfig = ActiveTabHasCloseButton | DockAreaHasCloseButton | OpaqueSplitterResize | XmlCompressionEnabled, ///< the default configuration
133134
};
134135
Q_DECLARE_FLAGS(ConfigFlags, eConfigFlag)

src/DockWidgetTab.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ namespace ads
5555
{
5656

5757
using tTabLabel = CElidingLabel;
58-
using tCloseButton = QPushButton;
5958

6059
/**
6160
* Private data class of CDockWidgetTab class (pimpl)
@@ -72,7 +71,7 @@ struct DockWidgetTabPrivate
7271
eDragState DragState = DraggingInactive;
7372
CFloatingDockContainer* FloatingWidget = nullptr;
7473
QIcon Icon;
75-
tCloseButton* CloseButton = nullptr;
74+
QAbstractButton* CloseButton = nullptr;
7675
QSpacerItem* IconTextSpacer;
7776

7877
/**
@@ -122,6 +121,21 @@ struct DockWidgetTabPrivate
122121
{
123122
return DockArea->dockManager()->configFlags().testFlag(Flag);
124123
}
124+
125+
/**
126+
* Creates the close button as QPushButton or as QToolButton
127+
*/
128+
QAbstractButton* createCloseButton() const
129+
{
130+
if (testConfigFlag(CDockManager::TabCloseButtonIsToolButton))
131+
{
132+
return new QToolButton();
133+
}
134+
else
135+
{
136+
return new QPushButton();
137+
}
138+
}
125139
};
126140
// struct DockWidgetTabPrivate
127141

@@ -143,7 +157,7 @@ void DockWidgetTabPrivate::createLayout()
143157
TitleLabel->setObjectName("dockWidgetTabLabel");
144158
TitleLabel->setAlignment(Qt::AlignCenter);
145159

146-
CloseButton = new tCloseButton();
160+
CloseButton = createCloseButton();
147161
CloseButton->setObjectName("tabCloseButton");
148162
// The standard icons do does not look good on high DPI screens
149163
QIcon CloseIcon;
@@ -154,9 +168,9 @@ void DockWidgetTabPrivate::createLayout()
154168

155169
CloseButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
156170
CloseButton->setVisible(false);
157-
#ifndef QT_NO_TOOLTIP
171+
#ifndef QT_NO_TOOLTIP
158172
CloseButton->setToolTip(QObject::tr("Close Tab"));
159-
#endif
173+
#endif
160174
_this->connect(CloseButton, SIGNAL(clicked()), SIGNAL(closeRequested()));
161175

162176
QFontMetrics fm(TitleLabel->font());

0 commit comments

Comments
 (0)