Window cannot shrink after expanding
-
(Some background info: I'm using MSVC2019 and C++)
As above. I'm expanding a window with a label displaying a pixmap, and trying to make the label scale to fit in the window. It works, but after I expand the label, I can only shrink the window until it would make the label shrink.
The settings on the label:
I assume the issue lies in how I'm setting the label's pixmap, but I can't find another way to make it scale properly.// excerpt from the definitions of a utility header void utl::setImage(QLabel* label, QImage img) { if (img.colorSpace().isValid()) img.convertToColorSpace(QColorSpace::SRgb); auto pixmap = QPixmap::fromImage(img); pixmap = pixmap.scaled(label->size(), Qt::AspectRatioMode::KeepAspectRatio); label->setPixmap(pixmap); }
// excerpt from the definitions of my QMainWindow class void DesktopFrontend::resizeEvent(QResizeEvent* resizeEvent) { utl::setImage(ui.imageDisplay, currentImage); }
I feel like the problem here is relatively trivial, but I've had a lot of difficulty finding good info on how to actually use Qt. Is there a good way to debug this kind of issue?
-
@EtheraelEspeon said in Window cannot shrink after expanding:
void DesktopFrontend::resizeEvent(QResizeEvent* resizeEvent)
{
utl::setImage(ui.imageDisplay, currentImage);
}In the first place, why you set the image on every resizeEvent?
I assume the issue lies in how I'm setting the label's pixmap
Could also be the settings of your parent layout. The sizePolicy is "Expanding". It will expand, but wont shrink further than the initial / content size (which updates every time you set the pixmap)
It works, but after I expand the label, I can only shrink the window until it would make the label shrink
Horizontally? Vertically? Or both?
-
@Pl45m4 said in Window cannot shrink after expanding:
In the first place, why you set the image on every resizeEvent?
This was the only way I could find to make the label's contents be resized to fit the window. The images I'm displaying are quite hi-res TIFFs, and at native resolution they can't fit on my 1080p monitor. I assume there's a better way to do this, but I couldn't find one.
Horizontally? Vertically? Or both?
Both. Here's a video of the behavior:
https://youtu.be/pe7nOlxXKcAAnd here's the configuration of another window exhibiting the same behavior
This is the full form file of that window, in case that's helpful:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>PointSelector</class> <widget class="QWidget" name="PointSelector"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>643</width> <height>528</height> </rect> </property> <property name="windowTitle"> <string>Point Selector</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QLabel" name="imageDisplay"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="text"> <string>No File</string> </property> <property name="alignment"> <set>Qt::AlignCenter|Qt::AlignHCenter|Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> </property> </widget> </item> <item> <widget class="Line" name="line"> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QLabel" name="label"> <property name="text"> <string>Left Click on head | Right Click on tail</string> </property> </widget> </item> <item> <widget class="QPushButton" name="confirmButton"> <property name="sizePolicy"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="minimumSize"> <size> <width>175</width> <height>0</height> </size> </property> <property name="text"> <string>Confirm</string> </property> </widget> </item> </layout> </item> </layout> </widget> <resources/> <connections/> </ui>