Files
HPPA/HPPA/AspectRatioLabel.cpp
2026-03-19 16:52:48 +08:00

29 lines
577 B
C++

#include "stdafx.h"
#include "AspectRatioLabel.h"
AspectRatioLabel::AspectRatioLabel(QWidget* parent)
: QLabel(parent)
{
setAlignment(Qt::AlignCenter);
}
void AspectRatioLabel::setOriginalPixmap(const QPixmap& pixmap)
{
m_originalPixmap = pixmap;
updateScaledPixmap();
}
void AspectRatioLabel::resizeEvent(QResizeEvent* event)
{
QLabel::resizeEvent(event);
updateScaledPixmap();
}
void AspectRatioLabel::updateScaledPixmap()
{
if (m_originalPixmap.isNull())
return;
setPixmap(m_originalPixmap.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}