如何保持QWidget(或QDialog)为其父窗口小部件居中? [英] How to keep a QWidget (or QDialog) centered to its parent widget?

查看:1944
本文介绍了如何保持QWidget(或QDialog)为其父窗口小部件居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想保持一个QWidget(或QDialog)居中其父窗口小部件。是真的需要连接到父窗口部件的信号还是有更容易的方式(要设置的东西)?

I want to keep a QWidget (or QDialog) centered to its parent widget. Is it really required to connect to signals of the parent widget or is there an easier way (something to set)?

推荐答案

保存在中心:

void MyMainWindow::moveEvent(QMoveEvent* event)
{
    const QPoint global = this->mapToGlobal(rect().center());
    waitDialog->move(global.x() - waitDialog->width() / 2, global.y() - waitDialog->height() / 2);
}

...其中 waitDialog 是我的Wait ...指示符的一个实例。这需要覆盖父代的 moveEvent 方法(这里 MyMainWindow )。

... where waitDialog is an instance of my "Wait..." indicator. This needs to override the moveEvent method of the parent (here MyMainWindow).

这篇关于如何保持QWidget(或QDialog)为其父窗口小部件居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆