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();
}
相关推荐
ziqibit3 分钟前
debian Live with Persistence 持久化U盘的debian系统
运维·debian
Shi_haoliu8 分钟前
SolidTime 在 Rocky Linux 9.5 上的完整部署流程
linux·运维·nginx·postgresql·vue·php·laravel
Lips61114 分钟前
2026.1.16力扣刷题
数据结构·算法·leetcode
Lkygo26 分钟前
LlamaIndex使用指南
linux·开发语言·python·llama
qq_254617771 小时前
nslookup 这个命令解析dns,和系统接口gethostbyname解析区别在哪?
linux·网络
kylezhao20191 小时前
C# 文件的输入与输出(I/O)详解
java·算法·c#
CodeByV1 小时前
【算法题】堆
算法
kaikaile19952 小时前
A星算法避开障碍物寻找最优路径(MATLAB实现)
数据结构·算法·matlab
HIT_Weston2 小时前
100、【Ubuntu】【Hugo】搭建私人博客:元信息&翻译(一)
linux·运维·ubuntu
C_心欲无痕2 小时前
Docker 的镜像与容器
运维·docker·容器