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();
}
相关推荐
历程里程碑1 小时前
LeetCode热题11:盛水容器双指针妙解
c语言·数据结构·c++·经验分享·算法·leetcode·职场和发展
Full Stack Developme3 小时前
Linux 多种压缩格式,优缺点和适用场景
linux·运维·服务器
旖旎夜光3 小时前
Linux(4)(下)
linux·学习
yBmZlQzJ7 小时前
财运到内网穿透域名解析技术机制与中立评估
运维·经验分享·docker·容器·1024程序员节
Shanxun Liao7 小时前
Cenots 7.9 配置多台 SSH 互信登陆免密码
linux·运维·ssh
j_xxx404_7 小时前
Linux:第一个程序--进度条|区分回车与换行|行缓冲区|进度条代码两个版本|代码测试与优化
linux·运维·服务器
一点晖光7 小时前
jenkins优化记录
运维·jenkins
wadesir8 小时前
Rust中的条件变量详解(使用Condvar的wait方法实现线程同步)
开发语言·算法·rust
looking_for__8 小时前
【Linux】Ext系列文件系统
linux
yugi9878388 小时前
基于MATLAB实现协同过滤电影推荐系统
算法·matlab