Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 ???

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...