Hello. I am using this code to center a dialog on the screen:
void centerWidgetOnScreen
(QWidget* widget
) {
widget->move(rect.center() - widget->rect().center());
}
void centerWidgetOnScreen(QWidget* widget)
{
QRect rect = QApplication::desktop()->availableGeometry(widget);
widget->move(rect.center() - widget->rect().center());
}
To copy to clipboard, switch view to plain text mode
(where widget is in fact a QDialog*).
But the dialog appears a bit to the right (maybe 10 pixels) and too low (maybe 30 pixels, considering also the task bar).
What am I doing wrong?
I also tried this:
QRect frect
=widget
->frameGeometry
();
frect.
moveCenter(QApplication::desktop()->availableGeometry
(widget
).
center());
//frect.moveCenter(QDesktopWidget().availableGeometry(widget).center());
widget->move(frect.topLeft());
QRect frect=widget->frameGeometry();
frect.moveCenter(QApplication::desktop()->availableGeometry(widget).center());
//frect.moveCenter(QDesktopWidget().availableGeometry(widget).center());
widget->move(frect.topLeft());
To copy to clipboard, switch view to plain text mode
But does not work under Linux. By the way, which should I use, QApplication::desktop() or QDesktopWidget()?
Bookmarks