PDA

View Full Version : best way to layer a few buttons over a background image?



qtpyqt
9th September 2010, 18:01
What would you recommend?
I need to have a background image and a few buttons scattered on top of the image.
:confused:
cheers

wysota
9th September 2010, 19:38
So what is the problem? You can put an image as a background of any widget and you can place widgets (like... say... buttons) in any widget.

qtpyqt
10th September 2010, 08:25
I was thinking what's the best layout to use if I want to stretch the window and have the image stretching along with the buttons (keeping the same relation of the buttons to the backgroun image)

wysota
10th September 2010, 09:06
First of all you don't have to use a layout if you don't want to so you can forbid the image from ever resizing. Second of all if the widget gets resized, the background will probably repeat and not stretch if you use what I suggested. To make it stretch, either use stylesheets or subclass the widget and do the painting of the background yourself in a way you want (i.e. stretching the image and keeping its aspect). Finally if you want full control over the placement of the buttons, reimplement the containing widget's resizeEvent() and do the positioning of the buttons yourself (without a layout) by calling resize()/move() or setGeometry().