PDA

View Full Version : Force QDialog to appear just to left of parent?



Eos Pengwern
12th December 2009, 20:55
Is it possible to force a QDialog to be displayed just to the left of its parent?

Usually, it seems that a QDialog will be displayed at an arbitrary location if it has no parent assigned, or within its parent if one is assigned. I'd like mine (which is a property-setter for a collection of Qwt graphs) to appear alongside the parent, so that it doesn't obscure the very plots that it is meant to be controlling. I can guarantee that there is always enough space for it between the edge of the screen and the edge of the parent.

I can think of lots of hard ways to do this (such as the brute force method of finding the parent's location, then finding the dialog's size, and calculating the dialog's position accordingly - though I'm not sure even this will work if I want to fix the dialog's position before it has been displayed for the first time). Is there an 'easy' (or at least, an elegant) way?

Thanks,
Stephen.

waynew
13th December 2009, 02:17
Probably because being a newbie I don't know any better, but....



QWidget::move(x,y);


in your dialog definition will set the position of the dialog to x,y.
Why not just pick an absolute position to the left of main window and set it?
Not elegant, but it will work.

Eos Pengwern
14th December 2009, 10:17
Thanks; if need be then that's what I'll do, but it will take a couple of lines of code to find calculate (x, y) by first of all finding the parent's location, then finding the dialog size, and then setting the dialog's location. Also, though I haven't tried it yet for this case, I have found in the past that size information returned for a widget before it has been displayed for the first time is not always reliable.

I'm still wondering if there's a more elegant way...