简体   繁体   English

QDialog 移除标题栏

[英]QDialog remove title bar

The net is flooded with similar questions, but for all I have seen nothing suits to solve the problem at hand.网络上充斥着类似的问题,但就我所知,没有什么适合解决手头的问题。

In my QT-C++ app, I have a mainwindow form with some functions, there is a QPushButton, Pressing which a QDialog opens.在我的 QT-C++ 应用程序中,我有一个带有一些功能的主窗口窗体,有一个 QPushButton,按下它会打开一个 QDialog。 Now, all functionalities in forms work fine, but I want the final application to be without any top title bar.现在,表单中的所有功能都可以正常工作,但我希望最终的应用程序没有任何顶部标题栏。 ie No Close / Minimize / Maximize Button.即没有关闭/最小化/最大化按钮。

In my main.cpp I have done --在我的main.cpp 中,我做了——

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    w.show();
    return a.exec();
}

as a result the mainwindow has become -结果主窗口变成了 -

在此处输入图片说明

For the dialog.cpp window, I have set -对于dialog.cpp窗口,我设置了 -

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
    //QDialog Dialog(0, Qt::CustomizeWindowHint|Qt::WindowTitleHint);  --- used this also; no use

    QDialog Dialog(0, Qt::FramelessWindowHint | Qt::Dialog);

But the title bar of QDialog remains, it looks like -但是 QDialog 的标题栏仍然存在,它看起来像 -

在此处输入图片说明

Where am I going wrong ???我哪里错了??? any ideas on how to remove the close button and the title bar ???关于如何删除关闭按钮和标题栏的任何想法???

I needed to do the same thing as this question for dialogs but I wanted a border on the dialog without the window bar.我需要为对话框做与这个问题相同的事情,但我想要一个没有窗口栏的对话框边框。 The solution was actually quite simple.解决方法其实很简单。 Just set the dialog's flags to Qt::CustomizeWindowHint:只需将对话框的标志设置为 Qt::CustomizeWindowHint:

dialog.setWindowFlags(Qt::CustomizeWindowHint);

You can also OR this with specific flags to further customize the windows appearance as noted in the documentation.您还可以将其与特定标志进行或以进一步自定义文档中所述的窗口外观。

Solved it with help from a friend, posting the answer for ready reference for someone in need ---在朋友的帮助下解决了这个问题,发布了答案以供有需要的人参考---

in the mainwindow.cpp when the Fetch button is pressed, the qdialog opens, I have set the properties there;在 mainwindow.cpp 中,当按下 Fetch 按钮时,qdialog 打开,我已经在那里设置了属性;

void MainWindow::on_pushButton_2_clicked()
{
    Dialog dialog;
    dialog.setModal(true);
    dialog.setWindowFlags(Qt::FramelessWindowHint);
    dialog.exec();
}

This did the trick --这成功了——

在此处输入图片说明

and the dialog --和对话——

在此处输入图片说明

I have had some problems with setting Qt::FramelessWindowHint flag, so I ended up with overriding resizeEvent instead of setting this flag:我在设置 Qt::FramelessWindowHint 标志时遇到了一些问题,所以我最终覆盖了 resizeEvent 而不是设置这个标志:

void  MyDialog::resizeEvent(QResizeEvent*)
{
    this->setMask(QRegion(this->rect()));
}
Dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM