Centering Screen

Archived bsnes development news, feature requests and bug reports. Forum is now located at
ZSNES Developer
ZSNES Developer
Posts: 3903
Joined: Tue Jul 27, 2004 10:54 pm
Location: Solar powered park bench

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

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( - (window->frameSize().width()  / 2), - (window->frameSize().height() / 2)