qt5 窗口启动居中显示

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();
}
相关推荐
HIT_Weston19 小时前
103、【Ubuntu】【Hugo】搭建私人博客:搜索功能(四)
linux·运维·ubuntu
旖旎夜光19 小时前
Linux(11)(中)
linux·网络
博大世界19 小时前
matlab结构体数组定义
数据结构·算法
txinyu的博客19 小时前
前置声明与 extern
linux·c++
Loo国昌19 小时前
【LangChain1.0】第九阶段:文档处理工程 (LlamaIndex)
人工智能·后端·python·算法·langchain
Zach_yuan19 小时前
面向对象封装线程:用 C++ 封装 pthread
开发语言·c++·算法
安特尼20 小时前
X 推荐算法分析
算法·机器学习·推荐算法
视觉震撼20 小时前
逐步指南:为大模型构建自动化知识图谱
运维·自动化·知识图谱
yeflx21 小时前
OpenMVS源码编译
运维
有泽改之_21 小时前
ssh命令使用
linux·运维·ssh