How to set absolute position of the widgets in qt

chai picture chai · Dec 1, 2010 · Viewed 52k times · Source

I am using QT to develop a rich UI application.

  1. I need to position widgets at absolute positions
  2. I should be able to put the widget in background / foreground to add a few effects.

Simple example would be, I have to show a boiler with the water level inside the feed tank.

  1. Take a feed tank image and embed in a label.
  2. Position a progress bar in the center of the feedtank to display water level.

Now in this case the progress bar would be in the foreground and the label in the background.

Regards,

Answer

Frank Osterfeld picture Frank Osterfeld · Dec 2, 2010

Use QWidget::move() to set the position, QWidget::resize() to set the size and reimplement the parent's resizeEvent() handler if you need to re-position the widgets if their parent resizes.