McLan
McLan

Reputation: 2688

How to prevent a pop-up dialog-box from changing its position?

In my application, I have a push-button labeled Insert that, when clicked, pops-up a dialog box for the user to write some information. In the bottom of the dialog box, there are Save and Exit buttons. When you click Exit, the dialog-box closes. If you click the Insert button again, the dialog box appears and so on.

The problem is that the dialog box keeps changing its position on the screen every time it's closed and then opened. The horizontal position is the same, however it keeps going down the vertical position couple of inches.

How to fix the position of this dialog-box ?!

Upvotes: 1

Views: 522

Answers (1)

Murphy
Murphy

Reputation: 3999

Placement of windows/dialogs is usually done by your window manager, often applying some kind of (pseudo-)intelligent algorithm. E. g. on KDE you have the choice between several settings, like Smart, Zero-Cornered, Random etc.

To make sure a Qt dialog is always placed at the same position on show you'll have to save and restore the position yourself, using QWidget::move() or QWidget::restoreGeometry(), usually from a reimplemented show() slot. Read the docs for this methods; this can be hairy WRT absolute/relative positions.

Upvotes: 3

Related Questions