Positioning in BoxLayout #12
-
I would like to know how to position elements inside a BoxLayout section, specifically an Image. BoxLayout documentation says:
This makes me think there's no way to horizontally position an element inside a horizontal BoxLayout. Is that true? What is the best way to proceed? In addition, Image documentation directly says an Image is automatically center-aligned. That means you cannot position yourself an image? Sorry for the dummy questions, the documentation is a bit confusing 😅 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
A horizontal BoxLayout is a layout you use when you've decided you want the items laid directly next to each other, left to right. It will put the second widget right next to the first one. So, when you say "there's no way to horizontally position an element inside a horizontal BoxLayout", that's kind of right (the hints are ignored) and kind of wrong (you precisely horizontally positioned all the elements when you chose a horizontal BoxLayout). You may be looking for a different layout to meet your needs. |
Beta Was this translation helpful? Give feedback.
-
The actual image is centred within the Image widget's bounding box, but you can position the image widget wherever you want (e.g. with a layout) so you still have control. Imagine a poster stuck to a poster board. The poster is always centred inside the posterboard, but the posterboard can be the same size as the picture and put anywhere on the wall. |
Beta Was this translation helpful? Give feedback.
As I understand (and we are getting to my limits): The BoxLayout will, if it can, fill itself with subwidgets. (It may have no choice if all the subwidgets specify a size.)
But putting the widget inside another Layout to control how it fits in the space allocated by the Box Layout is a sensible approach.