I am working in Qt 5.7 in C++ in QT Designer. In central widget I have two labels fulfilled with pictures. One picture is big (label), second is smaller, smaller (label_2) is in front of the bigger one. When I resize the MainWindow, the pictures are not adjusting its size. I was trying to adjust them using layouts, but my problem is that the smaller picture must overlay the bigger one (map and map position). And when I use layout, pictures are always put in a different place. How to force picture in the labels (label, label_2) adjusting its size depending on Main Windows without using a layout?
Asked
Active
Viewed 673 times
0
-
1Have you tried `QLabel::setScaledContents()` to scale pictures with layout? – ilotXXI Jul 11 '16 at 14:15
1 Answers
1
You can handle the resize events of the main window and set the labels geometry accordingly.
In this case, I suggest to reimplement the resizeEvent(QResizeEvent *event)
in the implementation of the widget created by the designer, to handle the resize events.
Example:
void MainWindow::resizeEvent(QResizeEvent *event)
{
QMainWindow::resizeEvent(event);
int x1, y1, w1, h1;
int x2, y2, w2, h2;
// compute the labels geometry
// you can get the old and the new window size
// calling event->oldSize() and event->size()
//....
label->setGeometry(x1, y2, w1, h1);
label_2->setGeometry(x2, y2, w2, h2);
}

Fabio
- 2,522
- 1
- 15
- 25