Qt 获取桌面的宽度
QRect deskRect = QApplication::desktop()->availableGeometry();
int width = deskRect.width()/2;
int heigth = deskRect.height()/2;
int CurWidth = this->width(); //this代表当前窗口本身
int CurHeigth = this->height();
this->setGeometry(width-CurWidth/2,heigth-CurHeigth/2,411,180);
头文件 #include <QApplication> 、#include <QDesktopWidget>加上,加上即可。
//获取屏幕中心 让提示框移动到中心
QRect deskRect = QApplication::desktop()->availableGeometry();
int width = deskRect.width()/2;
int heigth = deskRect.height()/2;
QPoint point(width,heigth);
QMessageBox msgbox(this);
msgbox.setWindowTitle(QString::fromLocal8Bit("提示"));
msgbox.setText(QString::fromLocal8Bit("巴啦啦能量,乌塔拉塔!"));
msgbox.move(point);
msgbox.exec();