mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Addes support for setting DockWidgetTab icon size via stylesheet
This commit is contained in:
parent
f6d3d6d34a
commit
aedbaec497
@ -51,7 +51,6 @@
|
||||
#include "DockManager.h"
|
||||
#include "IconProvider.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@ -77,6 +76,7 @@ struct DockWidgetTabPrivate
|
||||
QAbstractButton* CloseButton = nullptr;
|
||||
QSpacerItem* IconTextSpacer;
|
||||
QPoint TabDragStartPosition;
|
||||
QSize IconSize;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -186,6 +186,27 @@ struct DockWidgetTabPrivate
|
||||
DragStartMousePosition = _this->mapFromGlobal(GlobalPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the icon in case the icon size changed
|
||||
*/
|
||||
void updateIcon()
|
||||
{
|
||||
if (!IconLabel || Icon.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IconSize.isValid())
|
||||
{
|
||||
IconLabel->setPixmap(Icon.pixmap(IconSize));
|
||||
}
|
||||
else
|
||||
{
|
||||
IconLabel->setPixmap(Icon.pixmap(_this->style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, _this)));
|
||||
}
|
||||
IconLabel->setVisible(true);
|
||||
}
|
||||
|
||||
};
|
||||
// struct DockWidgetTabPrivate
|
||||
|
||||
@ -570,11 +591,7 @@ void CDockWidgetTab::setIcon(const QIcon& Icon)
|
||||
}
|
||||
|
||||
d->Icon = Icon;
|
||||
if (d->IconLabel)
|
||||
{
|
||||
d->IconLabel->setPixmap(Icon.pixmap(style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this)));
|
||||
d->IconLabel->setVisible(true);
|
||||
}
|
||||
d->updateIcon();
|
||||
}
|
||||
|
||||
|
||||
@ -688,6 +705,21 @@ void CDockWidgetTab::updateStyle()
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QSize CDockWidgetTab::iconSize() const
|
||||
{
|
||||
return d->IconSize;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CDockWidgetTab::setIconSize(const QSize& Size)
|
||||
{
|
||||
d->IconSize = Size;
|
||||
d->updateIcon();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace ads
|
||||
|
@ -31,6 +31,7 @@
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QFrame>
|
||||
#include <QSize>
|
||||
|
||||
#include "ads_globals.h"
|
||||
|
||||
@ -50,6 +51,7 @@ class ADS_EXPORT CDockWidgetTab : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool activeTab READ isActiveTab WRITE setActiveTab NOTIFY activeTabChanged)
|
||||
Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
|
||||
|
||||
private:
|
||||
DockWidgetTabPrivate* d; ///< private data (pimpl)
|
||||
@ -159,6 +161,20 @@ public:
|
||||
*/
|
||||
void updateStyle();
|
||||
|
||||
/**
|
||||
* Returns the icon size.
|
||||
* If no explicit icon size has been set, the function returns an invalid
|
||||
* QSize
|
||||
*/
|
||||
QSize iconSize() const;
|
||||
|
||||
/**
|
||||
* Set an explicit icon size.
|
||||
* If no icon size has been set explicitely, than the tab sets the icon size
|
||||
* depending on the style
|
||||
*/
|
||||
void setIconSize(const QSize& Size);
|
||||
|
||||
public slots:
|
||||
virtual void setVisible(bool visible) override;
|
||||
|
||||
|
@ -16,6 +16,7 @@ ads--CDockWidgetTab {
|
||||
border-style: solid;
|
||||
border-width: 0 1px 0 0;
|
||||
padding: 0 0px;
|
||||
qproperty-iconSize: 16px 16px;/* this is optional in case you would like to change icon size*/
|
||||
}
|
||||
|
||||
ads--CDockWidgetTab[activeTab="true"] {
|
||||
|
Loading…
Reference in New Issue
Block a user