Addes support for setting DockWidgetTab icon size via stylesheet

This commit is contained in:
Uwe Kindler
2020-10-31 13:56:16 +01:00
parent f6d3d6d34a
commit aedbaec497
3 changed files with 55 additions and 6 deletions

View File

@@ -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