QDialog remove title bar
Asked Answered
B

4

6

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. Now, all functionalities in forms work fine, but I want the final application to be without any top title bar. i.e. No Close / Minimize / Maximize Button.

In my main.cpp I have done --

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 -

enter image description here

For the dialog.cpp window, I have set -

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 -

enter image description here

Where am I going wrong ??? any ideas on how to remove the close button and the title bar ???

Bury answered 12/5, 2015 at 4:8 Comment(1)
Possible duplicate of How to hide titlebar of the QDialog window?Phenformin
B
4

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;

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

This did the trick --

enter image description here

and the dialog --

enter image description here

Bury answered 12/5, 2015 at 4:43 Comment(2)
nice it helped me solve a very different problem. Thanks :)Unite
The problem with this solution is that it won't allow you to move or resize the dialog, in case if you want to. I understand it's a dialog so maybe resizing won't be necessary, but moving it around the screen is important. But maybe it behaves differently on Mac. I'm talking about Windows.Kephart
R
6

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:

dialog.setWindowFlags(Qt::CustomizeWindowHint);

You can also OR this with specific flags to further customize the windows appearance as noted in the documentation.

Rumanian answered 5/10, 2015 at 17:58 Comment(1)
After this setting, the window cannot be dragged, how to realize dragging the window by pressing the left button of the mouse on the blank area ?Lindblad
B
4

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;

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

This did the trick --

enter image description here

and the dialog --

enter image description here

Bury answered 12/5, 2015 at 4:43 Comment(2)
nice it helped me solve a very different problem. Thanks :)Unite
The problem with this solution is that it won't allow you to move or resize the dialog, in case if you want to. I understand it's a dialog so maybe resizing won't be necessary, but moving it around the screen is important. But maybe it behaves differently on Mac. I'm talking about Windows.Kephart
M
2

I have had some problems with setting Qt::FramelessWindowHint flag, so I ended up with overriding resizeEvent instead of setting this flag:

void  MyDialog::resizeEvent(QResizeEvent*)
{
    this->setMask(QRegion(this->rect()));
}
Margaux answered 9/5, 2017 at 13:57 Comment(1)
how did you call this function ?Flourishing
H
2
Dialog->setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);

Homoio answered 8/2, 2021 at 15:35 Comment(1)
this isn't a great answer, it would help if you fleshed it out. see stackoverflow.com/help/how-to-answerBismarck

© 2022 - 2024 — McMap. All rights reserved.