qt5 窗口启动居中显示
main.cpp里面修改
#include "mainwindow.h" #include <QApplication> #include <QScreen> #include <QDesktopWidget> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; //w.show(); //移动窗体到屏幕中央 QRect rect = w.frameGeometry(); QDesktopWidget desktop; QPoint centerPoint = desktop.availableGeometry().center(); rect.moveCenter(centerPoint); w.move(rect.topLeft()); w.show(); return a.exec(); }
qt6.0
//移动窗体到屏幕中央 QRect rect = w.frameGeometry(); // QDesktopWidget desktop; QScreen* screen = QGuiApplication::primaryScreen(); QPoint centerPoint = screen->availableGeometry().center(); rect.moveCenter(centerPoint); w.move(rect.topLeft()); w.show();
欢迎讨论,相互学习。
cdtxw@foxmail.com