July 28, 2011
Qt : Show Window In Center Screen
I want to create a program in Qt when running show window in center screen. We must include header QStyle and QDesktopWidget to show window in center screen. This is a simple method how to create a program in Qt when running show window in center of screen :
#include <QtGui/QApplication> #include "runonlyone.h" //change with your include window application #include <QStyle> #include <QDesktopWidget> int main(int argc, char *argv[]) { QApplication a(argc, argv); runOnlyOne w; //change with your window application w.setGeometry(QStyle::alignedRect(Qt::LeftToRight, Qt::AlignCenter, w.size(), qApp->desktop()->availableGeometry())); w.show(); return a.exec(); }
You can change runOnlyOne with your window application. I am success to compile thisĀ Qt: Show Window In Center Screen program in Ubuntu with Qt 4.6.2.
Source: http://developer.qt.nokia.com/forums/viewthread/3386/