Make pixmap resizing label work

This commit is contained in:
hunbernd 2020-01-21 20:02:08 +01:00
parent 68e6ad4880
commit 69a2933590
3 changed files with 18 additions and 33 deletions

View File

@ -51,38 +51,15 @@
<number>0</number>
</property>
<item row="0" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QLabel" name="photoLabel">
<widget class="AspectRatioPixmapLabel" name="photoLabel">
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@ -207,9 +184,13 @@
<header>gui/common/AvatarWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>AspectRatioPixmapLabel</class>
<extends>QLabel</extends>
<header>util/aspectratiopixmaplabel.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../icons.qrc"/>
<include location="Posted_images.qrc"/>
</resources>
<connections/>

View File

@ -19,6 +19,7 @@
*******************************************************************************/
#include "AspectRatioPixmapLabel.h"
#include <iostream>
AspectRatioPixmapLabel::AspectRatioPixmapLabel(QWidget *parent) :
QLabel(parent)
@ -53,4 +54,6 @@ void AspectRatioPixmapLabel::resizeEvent(QResizeEvent * e)
{
if(!pix.isNull())
QLabel::setPixmap(scaledPixmap());
QLabel::resizeEvent(e);
//std::cout << "Information resized: " << e->oldSize().width() << 'x' << e->oldSize().height() << " to " << e->size().width() << 'x' << e->size().height() << std::endl;
}

View File

@ -29,13 +29,14 @@ class AspectRatioPixmapLabel : public QLabel
{
Q_OBJECT
public:
explicit AspectRatioPixmapLabel(QWidget *parent = 0);
virtual int heightForWidth( int width ) const;
virtual QSize sizeHint() const;
explicit AspectRatioPixmapLabel(QWidget *parent = nullptr);
virtual int heightForWidth( int width ) const override;
virtual QSize sizeHint() const override;
QPixmap scaledPixmap() const;
public slots:
void setPixmap ( const QPixmap & );
void resizeEvent(QResizeEvent *);
protected:
void resizeEvent(QResizeEvent *event) override;
private:
QPixmap pix;
};