K
K
Kirill H2016-12-16 18:53:41
Qt
Kirill H, 2016-12-16 18:53:41

How to spawn a static BackGround in Qt?

I am currently using the QGraphicsView graphic class.
In order to fill the background I use:

view->setBackgroundBrush(QPixmap(":/images/bg.jpg"));

The essence of the issue is that with such a display, the background is filled with copying the texture. I'm interested in a method when you can position a picture in the middle of the screen, without duplicating it and other deformation.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yapparov_Ilyas, 2016-12-17
@KirillHelm

QGraphicsView* view= new QGraphicsView;
QPixmap img;
img.load("some_image");
view->setBackgroundBrush(img.scaled(*QSize*));

Set the background exactly to the size of your widget, then image duplication can be avoided. If the window changes size, then override resizeEvent.
Also, you will most likely need to set the size of the work area setSceneRect, otherwise the background will expand indefinitely when the object leaves the window.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question