最近玩了一下qt5.2.1,顺着写点东西,关于这个版本设置程序主窗口居中
#include <QtGui/QGuiApplication> #include <QDebug> #include <QScreen> #include "qtquick2applicationviewer.h" int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QScreen *screen=app.screens()[0];//获取第一个屏幕 int width=screen->size().width();//得到屏幕的宽 int height=screen->size().height();//得到屏幕的高 QtQuick2ApplicationViewer viewer; viewer.setMainQmlFile(QStringLiteral("qml/untitled2/main.qml")); viewer.setPosition(width/2 - viewer.width()/2 , height/2 - viewer.height()/2 );//设置这个窗口的位置 viewer.show(); return app.exec(); }