View Full Version : Changing widget position overlay on another widget while screen is resizing

21st August 2015, 23:34
Good day experts

I am designing an application for a data acquisition system using Qt. i need to place led control controls on picture that show the layout of the acquisition system. actually the led indicate the state of some sensors(safe,warning,alarm) shown on the picture as marker. when the screen resizes meaning that the picture sizes increases i need these leds to follow the marker position so that a led is always on a given marker.

I have tried to reimplement the event resize method. I designed the gui with a given size, use that size width to position the led widget at a specific location on a marker when the gui is launched.When the users increases the screen size i tried to get the new screen width divide by some factor and passed it to the led for a new position. but the pos() only accept integers so the led cant be quite on the marker. also these seems to work for big difference between screen sizes change(the led approaches at least the marker). with small increments my algorithm the positioning is not working.

lastly, i tried to design the gui for two screen sizes. the one that its get when launched and the one that it will get when completely maximized. this seems to work. but only if you don't tried any other screen resized in between. i am thinking of blocking any other screen sizes but these two.I have attached a picture of what i trying to do.

Been looking around and trying stuff don't seems to solve my problem.any help would be much appreciated.

Thanks in advance.:confused:

22nd August 2015, 11:27
How do you display the images?

How do you resize them? I.e. is it the same image and it gets scaled or do you load a new image for the new size?


24th August 2015, 03:06
Hello thanks for considering my issue.

Actually the markers are on an image that is the pixmap of a qlabel. the leds are widgets parented by the qlabel. The image resizes as the application screen is resized. no new image. since the qlabel is the app central widget it resizes as the app resizes i think.I then tried to use resize event to change the leds positions

Again, Thanks for helping out!


25th August 2015, 08:48
Ah, so the image is drawn and resized by a QLabel?

I would suggest a different approach:
- create a custom QWidget derived class
- let it scale and draw the image
- let it also draw the "leds"

You can then also experiement with scaling the painter and drawing image and leds in their original coordinates.


25th August 2015, 11:12
hello anda_skoa!

I am not quite sure if i understand what you saying. The Qlabel image i am getting it from a resource file.Do you mean using qpainter to redraw the leds each time the screen is resized? the custom qwidget, should it just be a class that inherit from qwidget?

can you please explain a bit more or provide a sample?