[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);
    @



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

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

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

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    Widget w;
    w.setWindowTitle("Shreepoorna");
    w.setWindowFlags(Qt::FramelessWindowHint);
    w.show();

    return a.exec();
    

    }

    Widget::Widget(QWidget *parent) :
    QWidget(parent)
    {
    QPushButton *pushButton = new QPushButton("ClickMe");
    connect(pushButton,SIGNAL(clicked()),this,SLOT(setFlags()));
    }
    void Widget::setFlags(){
    qDebug() << "Hello"<<endl;
    this->setWindowFlags(windowFlags() & ~Qt::FramelessWindowHint);
    show();
    }@

    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);
    show();@

    Thank you both once again.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.