QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgspixmaplabel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  ----------------------------------------------------
4  date : 7.9.2015
5  copyright : (C) 2015 by Matthias Kuhn
6  email : matthias (at) opengis.ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgspixmaplabel.h"
17 
18 
20  : QLabel( parent )
21 {
22  this->setMinimumSize( 1, 1 );
23 }
24 
26 {
27  bool sizeChanged = ( p.size() != mPixmap.size() );
28  mPixmap = p;
29 
30  if ( sizeChanged )
31  {
33  }
34 
35  QLabel::setPixmap( mPixmap.scaled( this->size(),
36  Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
37 }
38 
40 {
41  if ( mPixmap.isNull() )
42  return 0;
43 
44  return (( qreal )mPixmap.height()*width ) / mPixmap.width();
45 }
46 
48 {
49  if ( mPixmap.isNull() )
50  return QSize( 0, 0 );
51 
52  int w = this->width();
53  return QSize( w, heightForWidth( w ) );
54 }
55 
57 {
59  QLabel::setPixmap( mPixmap.scaled( this->size(),
60  Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
61 }
virtual QSize sizeHint() const override
An optimal size for the widget.
QSize size() const
void setPixmap(const QPixmap &)
int width() const
void updateGeometry()
void setPixmap(const QPixmap &)
virtual int heightForWidth(int width) const override
Calculates the height for the given width.
int width() const
void setMinimumSize(const QSize &)
QPixmap scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
bool isNull() const
int height() const
virtual void resizeEvent(QResizeEvent *event)
void resizeEvent(QResizeEvent *) override
QgsPixmapLabel(QWidget *parent=nullptr)