Resize photoview to the size of embedded image

This commit is contained in:
hunbernd 2020-01-21 21:23:42 +01:00
parent 69a2933590
commit 83b18509e2
3 changed files with 7 additions and 10 deletions

View file

@ -62,6 +62,7 @@ void PhotoView::setPixmap(const QPixmap& pixmap)
else{ else{
ui->photoLabel->setPixmap(pixmap); ui->photoLabel->setPixmap(pixmap);
} }
this->adjustSize();
} }
void PhotoView::setTitle(const QString& text) void PhotoView::setTitle(const QString& text)

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>565</width> <width>346</width>
<height>464</height> <height>107</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -38,7 +38,7 @@
<item row="1" column="0" colspan="2"> <item row="1" column="0" colspan="2">
<widget class="QFrame" name="frame"> <widget class="QFrame" name="frame">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -55,9 +55,6 @@
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -142,7 +139,7 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>398</width> <width>0</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>

View file

@ -31,7 +31,7 @@ AspectRatioPixmapLabel::AspectRatioPixmapLabel(QWidget *parent) :
void AspectRatioPixmapLabel::setPixmap ( const QPixmap & p) void AspectRatioPixmapLabel::setPixmap ( const QPixmap & p)
{ {
pix = p; pix = p;
QLabel::setPixmap(scaledPixmap()); QLabel::setPixmap(pix);
} }
int AspectRatioPixmapLabel::heightForWidth( int width ) const int AspectRatioPixmapLabel::heightForWidth( int width ) const
@ -41,8 +41,7 @@ int AspectRatioPixmapLabel::heightForWidth( int width ) const
QSize AspectRatioPixmapLabel::sizeHint() const QSize AspectRatioPixmapLabel::sizeHint() const
{ {
int w = this->width(); return QSize(pix.width(), pix.height());
return QSize( w, heightForWidth(w) );
} }
QPixmap AspectRatioPixmapLabel::scaledPixmap() const QPixmap AspectRatioPixmapLabel::scaledPixmap() const