PDA

View Full Version : Widget->show() place widget to top left corner (not on the top of mainwindow)



binaural
28th May 2010, 17:03
Hi,

I have a main window and on menu item click I open new modal window with method show(). Sometimes happens that application is in the middle of the screen but new window is opened on the top left corner. I would need to always open widget near the mainwindow. It's possible to have such a behaviour? I'm using Qt 4.6.2 on winXP. Thanks

high_flyer
28th May 2010, 17:58
You parent your pupup dialog with the window/dialog you want to to be centered on.
Or, if parenting is not wanted for what ever reason, you can test its position and move it, either by using move() or setGeometry().

binaural
28th May 2010, 21:34
Hi,

popup dialogs are parent for mainwindow. So it should work and show popup near the mainwindow.
I'm using it in that way in main window constructor:


/* new dialog */
this->about = new DialogAbout(parent);


Then slot for click I do:


about->show();


I have similar for 4 more widget and they are always shown correctly.

How can I check position of main window to use your second advice?
I try to use dialog->pos() but always get QPoint(0,0).

Thanks

Zlatomir
28th May 2010, 21:43
I'm not sure that i understand your code, but:
this:

this->about = new DialogAbout(parent);
shouldn't be like this?

this->about = new DialogAbout(this);

binaural
29th May 2010, 15:59
Hi,

it doesn't help. Any other advices ? Thanks

Zlatomir
29th May 2010, 16:19
If you can't post your code, please make a small project that has that behavior and post it.

binaural
29th May 2010, 17:24
No problem. See attachment.

alexisdm
29th May 2010, 19:07
Your form should inherit from QDialog, so it can be a top-level window, have a parent and be centered on top of that parent.

And as Zlatomir said, you should pass this to its constructor:

this->form = new Form(this);

binaural
29th May 2010, 19:17
Hi,

I think (parent) is OK. If I use your proposals then my mainwindow is mixed with form widget. Did you try it you just assume it should be in that way? Thanks :cool:

Zlatomir
29th May 2010, 19:32
If you make it a dialog it works like you want (or at least like i think you want)

And i don't recommend to make the Form member in MainWindow (check the code)
You can emit a signal (a MainWindow signal) when member button is clicked, and connect that with the show() slot of your Form (that's what on_bla_bla slots do with auto-connect, or you can manualy connect them)

binaural
29th May 2010, 19:42
Hmm, I think this doesn't solve my situation. I need to mention I use 5 same widgets which I show with show() method and only 1 of them make a problem (is displayed at the top left corner). With my attachment I would like to show you whats the problem. It's rather strange for me why this happens because I use it is same way.