PDA

View Full Version : Hot to Set my QMainWindow in center



santhoshv84
24th May 2008, 07:00
Hi friends,

I am new to QT. I am doing an application. I want to show my window in the monitor center.

Could any one tell me how to do this.
I know this in VC++. But not in QT.

Thanks in Advance.
V. Santhosh

init2null
24th May 2008, 07:24
Hi! Here is the code I use for this purpose. Change .85 to control how much of the display you want your window to fill.



int screen = 0;
QWidget *w = topLevelWidget();
QDesktopWidget *desktop = QApplication::desktop();
if (w) {
screen = desktop->screenNumber(w);
} else if (desktop->isVirtualDesktop()) {
screen = desktop->screenNumber(QCursor::pos());
} else {
screen = desktop->screenNumber(this);
}
QRect rect(desktop->availableGeometry(screen));
resize(int(rect.width() * .85), int(rect.height() * .85));
move(rect.width()/2 - frameGeometry().width()/2,
rect.height()/2 - frameGeometry().height()/2);

santhoshv84
24th May 2008, 07:54
Hi,

Its working fine. Thanks you once again.

Thanks and regards.
V. Santhosh