Remove contents margins from sizehint when preserving aspect ratio

* This prevents a feedback loop where the label resizes wider to make
  room for the margins, then the margins get bigger to keep the image
  centred/scaled properly, etc.
This commit is contained in:
baldurk
2017-07-12 18:26:05 +01:00
parent bcd08f77a6
commit 79979b60c7
2 changed files with 23 additions and 0 deletions
+20
View File
@@ -33,6 +33,26 @@ RDLabel::~RDLabel()
{
}
QSize RDLabel::sizeHint() const
{
QSize sz = QLabel::sizeHint();
if(m_preserveRatio)
sz.setWidth(sz.width() - contentsMargins().left() - contentsMargins().right());
return sz;
}
QSize RDLabel::minimumSizeHint() const
{
QSize sz = QLabel::minimumSizeHint();
if(m_preserveRatio)
sz.setWidth(sz.width() - contentsMargins().left() - contentsMargins().right());
return sz;
}
void RDLabel::mousePressEvent(QMouseEvent *event)
{
emit(clicked(event));
+3
View File
@@ -33,6 +33,9 @@ public:
explicit RDLabel(QWidget *parent = 0);
~RDLabel();
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
void setPreserveAspectRatio(bool preserve) { m_preserveRatio = preserve; }
bool preserveAspectRatio() { return m_preserveRatio; }
signals: