QLabel not showing image correctly
-
Hello everybody,
I have written an application, that links statically to the plug-in, that is of my own code. Everything is done in Qt. My plug-in has KDevice class, which has *QWidget face() function. The widget this function returns has QLabel on it with an image. The image is taken from resource inside plug-in. This face gets added to some layout of the app on start-up after loading the plug-in.
The problem here is that the image in QLabel gets resized to whatever size Qt wants. Especially if my file is portrait of landscape type, not a rectangle. My goal is to make Qt keep the size of the image.
-
Hi,
There are hasWidthForHeight and hasHeightForWidth functions for QLabel. When you do need to set the constraints, subclass the QLabel and redefine those functions to keep the aspect ratio -
Thanks, but maybe I should use another widget?
-
Ha! I got it, my fault. I was setting QLabel's image like that:
@
ui->label->setPixmap(pic->scaleToHeigth(200));
@instead of correct
@
ui->label->setPixmap(pic);
@May this post be helpful to someone else :)