2024-11-29 15:18:09 +00:00
|
|
|
|
# Tutorials {#tutorials}
|
2021-04-14 14:04:09 +00:00
|
|
|
|
|
2024-11-29 15:18:09 +00:00
|
|
|
|
## (Scalable) graphics
|
2021-04-14 14:04:09 +00:00
|
|
|
|
|
|
|
|
|
QSkinny offers support for scalable graphics, i.e. rendering SVGs that
|
|
|
|
|
adapt to a specific size. This means that when a graphic is embedded in
|
|
|
|
|
a layout, it can change its size when the layout is growing or
|
|
|
|
|
shrinking, while still maintaining a correct aspect ratio.
|
|
|
|
|
|
|
|
|
|
Imagine the following code, which produces the image depicted below:
|
|
|
|
|
|
2024-11-29 15:18:09 +00:00
|
|
|
|
```
|
2021-04-14 14:04:09 +00:00
|
|
|
|
auto horizontalBox = new QskLinearBox( Qt::Horizontal );
|
|
|
|
|
horizontalBox->setPreferredSize( { 200, 75 } );
|
|
|
|
|
|
|
|
|
|
QImage image1( ":/images/cloud.svg" );
|
|
|
|
|
QskGraphic graphic1 = QskGraphic::fromImage( image1 );
|
|
|
|
|
auto* label1 = new QskGraphicLabel( graphic1, horizontalBox );
|
|
|
|
|
label1->setSizePolicy( QskSizePolicy::ConstrainedPreferred, QskSizePolicy::Expanding );
|
|
|
|
|
|
|
|
|
|
QImage image2( ":/images/train.svg" );
|
|
|
|
|
QskGraphic graphic2 = QskGraphic::fromImage( image2 );
|
|
|
|
|
auto* label2 = new QskGraphicLabel( graphic2, horizontalBox );
|
|
|
|
|
label2->setSizePolicy( QskSizePolicy::ConstrainedPreferred, QskSizePolicy::Expanding );
|
|
|
|
|
...
|
2024-11-29 15:18:09 +00:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**graphics with preferred size**
|
2021-04-14 14:04:09 +00:00
|
|
|
|
|
2024-11-29 15:18:09 +00:00
|
|
|
|

|
2021-04-14 14:04:09 +00:00
|
|
|
|
|
|
|
|
|
When resizing the window, the graphics will scale according to the size
|
|
|
|
|
available in the layout:
|
|
|
|
|
|
2024-11-29 15:18:09 +00:00
|
|
|
|
**graphics bounded by width**
|
|
|
|
|
|
|
|
|
|

|
2021-04-14 14:04:09 +00:00
|
|
|
|
|
2024-11-29 15:18:09 +00:00
|
|
|
|
**graphics bounded by height**
|
|
|
|
|
|
|
|
|
|

|
2021-04-14 14:04:09 +00:00
|
|
|
|
|
|
|
|
|
Since we set the horizontal size policy of the graphics to
|
|
|
|
|
`ConstrainedPreferred`, the scaling is done through QskGraphic’s
|
|
|
|
|
`widthForHeight()` methods to maintain the correct aspect ratio. If we
|
|
|
|
|
had set the vertical policy to `ConstrainedPreferred` and the horizontal
|
|
|
|
|
one to e.g. `Expanding`, the layout would have queried the
|
|
|
|
|
`heightForWidth()` method instead.
|
|
|
|
|
|
|
|
|
|
Of course non-scalable graphics like PNGs and JPGs are also supported:
|
|
|
|
|
|
2024-11-29 15:18:09 +00:00
|
|
|
|
```
|
2021-04-14 14:04:09 +00:00
|
|
|
|
QImage image( "background.jpg" );
|
|
|
|
|
QskGraphic graphic = QskGraphic::fromImage( image );
|
|
|
|
|
...
|
2024-11-29 15:18:09 +00:00
|
|
|
|
```
|