如何居中QDialog
How to center QDialog?
我正在尝试将我的QDialog居中。
这是我使用的代码:
QRect screenGeometry = QApplication::desktop()->screenGeometry();
int x = (screenGeometry.width() - this->width()) / 2;
int y = (screenGeometry.height() - this->height()) / 2;
this->move(x, y);
但是我没有在适当的位置进行对话。当我打印对话框的宽度和高度值时,我注意到它们比实际值小得多。为了检查某些东西是否以错误的方式工作,我更改了它的几何形状:
this->setGeometry(100,100,this->width(),this->height());
我的对话缩小了...
有人可以告诉我发生了什么吗?
QRect screenGeometry = QApplication::desktop()->screenGeometry();
QRect windowRect = rect();
首先获取您自己的窗口 rect 的副本。
windowRect.moveCenter(screenGeometry.center());
将副本移动到屏幕矩形的中心。
move(windowRect.topLeft());
执行实际移动:将窗口左上角设置为计算出的左上点。无需调整大小。
相关文章:
- 函数何时会在c++中包含stack_Unwind_Resume调用
- Python中的for循环与C++有何不同
- 在C++中释放内存期间,迭代器与指针有何不同
- 自定义对话框(源自QDialog)不会关闭(Android)
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- QDialog 不能在 Windows 上退出,但在 MacOS 上不能退出/
- 类中的 C++ int 被设置为值,似乎不知从何而来
- -fvisibility-inline-hidden 与 gcc 中的 -fvisibility=hidden 有何不同
- 使用 cv::不扭曲不失真和居中图像
- 如何在C++中居中输出控制台窗口
- QDialog自行关闭,我该如何解决?
- 收益率和回报有何不同?
- 覆盖私有功能,它与受保护功能有何不同?
- 将 1 居中放在顶部
- Qt5自定义QDialog,不使用qt创建器
- C++ 如何居中文本输出
- 擦除删除成语的性能增益从何而来
- 当按下QDialog取消或确定时如何调用函数?
- 如何根据标题长度调整QDialog的大小?
- 如何居中QDialog