Toolbox Qt
Loading...
Searching...
No Matches
Public Slots | Public Member Functions | List of all members
tbq::LabelScl Class Reference

Label that will properly scale image or animation. More...

Inheritance diagram for tbq::LabelScl:
Inheritance graph
[legend]
Collaboration diagram for tbq::LabelScl:
Collaboration graph
[legend]

Public Slots

void resizeEvent (QResizeEvent *event) override
 

Public Member Functions

 LabelScl (QWidget *parent=nullptr)
 
const QPixmap & getPixmap () const
 Use to get original image.
 
QPixmap getPixmapScaled () const
 Use to get image scaled to fit inside the label.
 
void animPlay (bool start)
 Use to start/stop animation set.
 
void animStart ()
 Use to play animation set.
 
void animStop ()
 Use to play animation set.
 
void setImg (const QPixmap &pixmap)
 Set image to use via a QPixmap.
 
void setImg (const QImage &img)
 Set image to use via a QImage.
 
void setImg (const QImage *img)
 Set image via a pointer to QImage.
 
void setAnimation (const QString &animation)
 Set animation to use.
 
void setTextAlt (const QString &text)
 Set text to display when no image has been set.
 
virtual int heightForWidth (int width) const override
 
virtual QSize sizeHint () const override
 

Detailed Description

Label that will properly scale image or animation.

Include with:

#include "toolboxqt/widgets/labelscl.h"

QLabel doesn't behave properly when using it to display an image (or animation) that is loaded at runtime. Since size of image is not known when layout is rendered, QLabel size will be wrong and will not be properly updated when finally rendering an image (either too small, too big or not properly scaled). This class will manage this issue.

Note
Note that this class will be useful for QLabel containing image which are loaded at runtime. The described issue do not happen when image is available at compile-time.

Member Function Documentation

◆ animPlay()

void tbq::LabelScl::animPlay ( bool  start)

Use to start/stop animation set.

Parameters
[in]startSet to true to play animation, otherwise it will be stopped
See also
setAnimation()
animStart(), animStop()

◆ animStart()

void tbq::LabelScl::animStart ( )

Use to play animation set.

See also
setAnimation()
animStop()
animPlay()

◆ animStop()

void tbq::LabelScl::animStop ( )

Use to play animation set.

See also
setAnimation()
animStart()
animPlay()

◆ getPixmap()

const QPixmap & tbq::LabelScl::getPixmap ( ) const

Use to get original image.

Returns
Return reference to original image
See also
getPixmapScaled()
setImg()

◆ getPixmapScaled()

QPixmap tbq::LabelScl::getPixmapScaled ( ) const

Use to get image scaled to fit inside the label.

Returns
Returns image scaled to fit inside the available space of the label

◆ setAnimation()

void tbq::LabelScl::setAnimation ( const QString &  animation)

Set animation to use.

Parameters
[in]animationPath to animation ressource
See also
animPlay()
animStart(), animStop()

◆ setImg() [1/3]

void tbq::LabelScl::setImg ( const QImage &  img)

Set image to use via a QImage.

Parameters
[in]imgImage to use inside the label. This value will be copied.

◆ setImg() [2/3]

void tbq::LabelScl::setImg ( const QImage *  img)

Set image via a pointer to QImage.

Parameters
[in]imgPointer to image to use.
If nullptr, nothing will be perform.
Caller don't need to keep a reference to the object, value is copied.

◆ setImg() [3/3]

void tbq::LabelScl::setImg ( const QPixmap &  pixmap)

Set image to use via a QPixmap.

Parameters
[in]pixmapPixmap image to use inside the label. Pixmap image will be copied.

◆ setTextAlt()

void tbq::LabelScl::setTextAlt ( const QString &  text)

Set text to display when no image has been set.

Parameters
[in]textText to display when no image has been set.

The documentation for this class was generated from the following files: