Reputation: 13575
With Qt, I can open a dialog at the center position of its parent widget. However, when I move the parent widget to the right-lower corner and possibly its center is out of screen, the dialog is opened out of screen. This make the interaction with the dialog hard. I may treat this case specially when I detect it. How to detect if the dialog or part of the dialog is out of screen and how to move the dialog at a proper position?
Upvotes: 1
Views: 432
Reputation: 32655
You can use move() to position your dialog at the center of screen by:
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
QRect screenGeometry(QApplication::desktop()->screenGeometry());
this->move(-50000,-50000);
this->show();
this->move((screenGeometry.width() - this->width()) / 2.0,
(screenGeometry.height() - this->height()) / 2.0);
}
Because of not being able to query a window for its size before its been shown, first you should move the window to somewhere far outside the screen, next you show it and then move it to the center.
Upvotes: 1
Reputation: 8994
How to detect if the dialog or part of the dialog is out of screen
Use QDesktopWidget
to obitain screen coordinates
how to move the dialog at a proper position?
Use QWidget::move
method
Possible, you should not use popups at all? Or you should provide positioning managment to OS?
Upvotes: 1