Centering Screen

Archived bsnes development news, feature requests and bug reports. Forum is now located at http://board.byuu.org/
Locked
Nach
ZSNES Developer
ZSNES Developer
Posts: 3904
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench
Contact:

Centering Screen

Post by Nach »

byuu, see this:
QDesktopWidget * QApplication::desktop () [static]

Returns the desktop widget (also called the root window).

Note that the desktop may be composed of multiple screens, so it would be incorrect, for example, to attempt to center some widget in the desktop's geometry. QDesktopWidget has various functions for obtaining useful geometries upon the desktop, such as QDesktopWidget::screenGeometry() and QDesktopWidget::availableGeometry().
Not sure if you know this already or not.
May 9 2007 - NSRT 3.4, now with lots of hashing and even more accurate information! Go download it.
_____________
Insane Coding
byuu

Post by byuu »

Yeah, but thanks anyway.

Code: Select all

//show specified window in the center of the screen.
void Utility::showCentered(QWidget *window) {
  QRect deskRect = QApplication::desktop()->availableGeometry(window);

...

  window->move(
    deskRect.center().x() - (window->frameSize().width()  / 2),
    deskRect.center().y() - (window->frameSize().height() / 2)
  );
Locked