The following code snippet is doing what you are looking for:
// set width and height of your window
int width = ...
int height = ...
// alternatively you can get your window size
// if already set:
/* adjustSize(); // necessary to get updated size
QRect frame = geometry();
int width = frame.width();
int height = frame.height(); */
// get screen geometry
// we center window on screen
int x = ( screen.width - width ) >> 1;
int y = ( screen.height - height ) >> 1;
setGeometry( x, y, width, height );
// set width and height of your window
int width = ...
int height = ...
// alternatively you can get your window size
// if already set:
/* adjustSize(); // necessary to get updated size
QRect frame = geometry();
int width = frame.width();
int height = frame.height(); */
// get screen geometry
QRect screen = QApplication::desktop()->screenGeometry();
// we center window on screen
int x = ( screen.width - width ) >> 1;
int y = ( screen.height - height ) >> 1;
setGeometry( x, y, width, height );
To copy to clipboard, switch view to plain text mode
Bookmarks