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();
}
相关推荐
2301_795167205 小时前
Python 高手编程系列一十八:子类化内置类型
linux·windows·python
某林2125 小时前
在slam建图中为何坐标base_link,laser,imu_link是始终在一起的,但是odom 会与这位三个坐标在运行中产生偏差
人工智能·算法
想看一次满天星5 小时前
阿里140-n值纯算
爬虫·python·算法·网络爬虫·阿里140
Keep__Fighting5 小时前
【机器学习:逻辑回归】
人工智能·python·算法·机器学习·逻辑回归·scikit-learn·matplotlib
想唱rap5 小时前
C++之红黑树
开发语言·数据结构·c++·算法
赖small强5 小时前
【Linux驱动开发】Linux DMA 技术详解与驱动开发实战
linux·dma·直接内存访问
斌蔚司李6 小时前
笔记本、台式机、平板二合一?Mac、Win、Linux?
linux·macos·电脑
DeeplyMind6 小时前
AMD rocr-libhsakmt分析系列6-2:共享机制-import
linux·amdgpu·dma-buf·rocm·kfd·rocr
sin_hielo6 小时前
leetcode 3623
算法·leetcode·哈希算法
Dillon Dong6 小时前
【超详细】Ubuntu 上 MySQL 5.7 升级 MySQL 8 完整指南
linux·mysql·ubuntu