Can't center QDialog.
-
Could somebody help me?
I defined a customDialog that inherited from QDialog. I want it to be frameless and topmost. But its location is (0, 0) by default. I want it to be centered.
Here is the main code.
customDialog::customDialog(QWidget *parent)
QDialog(parent)
{
ui->setupui(this);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::Dialog);
}mainWindow::showDialog()
{
customDialog dialog(this);
dialog.exec();
}My environment:
Ubuntu 16.04
Thanks
-
This post is deleted!
-
You need to work with setGeometry(..) function. I don't see anything specific to center it.
-
Thank you!
If I don't setWindowFlags, the dialog show in the center by default. I don't know the reason, but I think there should something I can do to fix it. But I don't know.
What's more, I test it on Windows system, and it works.
-
@Qingshui-Kong said in Can't center QDialog.:
What's more, I test it on Windows system, and it works.
Qt::X11BypassWindowManagerHint
I doubt this one works on Wndows. And usually the window manager positions the dialog centered. -
@Qingshui-Kong
If you override showEvent, you must call the same function of the base class. Or it will skip the same function of the base class. Then there will be some bugs.