PDA

View Full Version : how to fix widget location



ht1
21st November 2007, 01:19
Hello.
I'd like the top left corner of my widget (a QLabel) to stay fixed relative to the main layout so that when I 1) resize the window, 2) change the size of the widget, 3) change the identity of the widget, the absolute coordinate (relative to the main layout) of my widget is not changed. I know that stretch can't do what I want.
Thanks in advance!

mchara
21st November 2007, 07:57
Could you write some more about your window?
Are you using layout, which one if you do, how widgets are places on window(is your label topmost of leftmost, or is it placed elsewhere)?
and what is actual behavior?

ht1
21st November 2007, 15:37
Hi Mchara,

Thanks for your response.
My main layout is QVBoxLayout, this contains two QHBoxLayouts. The top QHBoxLayout contains QLabel which is a QPixmap. I crop this pixmap with mouse and I'd like it to stay in the top left corner of my window (whatever I do to it). When I crop my pixmap I use mapFromParent to get the local coordinates. If the pixmap jumps around in the window (while zooming or cropping) it's very difficult to keep the coordinates straight. That's why I'd like to nail the top left corner of my pixmap to the main window.
I know there might be other ways to reliably obtain the coorinates and fixing the pixmap may not sound critical for that but I'd really prefer this approach (the reason being that other changes will negatively affect the program of which the pixmap is part).
Thanks again.

mchara
22nd November 2007, 08:10
so, u may try to set sizepolicies in a different way
i.e. QSizePolicy::Minimum in both directions shall keep widget's size expanded to whole free place in your window with pixmap in top-left corner (The widget,s size should be larger than pixmap's size).
You may also consider puting QLabel with pixmap into QScrollArea - you'll get automatically scrollbars if pixmap would be larger than widget.