How to hide titlebar of the QDialog window? [duplicate]

放肆的年华 提交于 2020-01-26 02:29:59

问题


I show a dialog in my qt application on menu action click window is appearing perfectly but I want to hide its title bar as it is just a sub-window inside main window.

I tried :

this->setWindowFlags(Qt::Window |Qt::FramelessWindowHint);

In dialog constructor:

ui->setupUi(this);
this->setWindowState (Qt::WindowActive);
setWindowModality(Qt::ApplicationModal);
setAttribute (Qt::WA_DeleteOnClose);
this->setWindowFlags(Qt::Window |Qt::FramelessWindowHint) ; // 

This does remove the title bar but it also hides the main window, which is bad for my application.

How can I hide dialog title bar without disturbing the base main window of the application?


回答1:


 QDialog *dialog(new QDialog /* this should be your dialog class youve created obviously*/));
 dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
 dialog->show();



回答2:


You're missing the CustomizeWindowHint.

As you can see from the source code here (line 1035) for QWidget, it decides what to do depending upon that flag. So I suggest trying this: -

setWindowFlags(Qt::Window | Qt::CustomizeWindowHint); 


来源:https://stackoverflow.com/questions/26015880/how-to-hide-titlebar-of-the-qdialog-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!