Qt World Summit: Submit your Presentation

[SOLVED]Hide and restore the mainwindow title bar

  • Hi all,

    I am trying out something like hiding the mainwindow title bar and when I need it to restore it.

    I tried hiding the title bar using the following code:
    @MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent), Qt::FramelessWindowHint),
    ui(new Ui::MainWindow)@

    and also I tried with setwindow flags :
    @setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);@

    Both worked fine.

    But I am not getting how to restore or unhide the title bar.
    Can anyone suggest me how will I do it?

    Thank you.

  • Moderators

    setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);

  • Qt Champions 2017

    You need to re-call show() function after trying the following. Otherwise it window vanishes.

    this->setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);

    @Here is the sample with one of my use case.

    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    Widget w;

    return a.exec();


    Widget::Widget(QWidget *parent) :
    QPushButton *pushButton = new QPushButton("ClickMe");
    void Widget::setFlags(){
    qDebug() << "Hello"<<endl;
    this->setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);

    Also you can look at the WindowsFlags example in example directory of Qt installation.

  • Hi,

    Thank you both for your reply. With the following code as you both stated I was able to get back the top bar.

    @setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);

    Thank you both once again.

Log in to reply