Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Hide and restore the mainwindow title bar
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Hide and restore the mainwindow title bar

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 14.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ChaitraMohan
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        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.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        YunusY 1 Reply Last reply
        0
        • C Offline
          C Offline
          ChaitraMohan
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • dheerendraD dheerendra

            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&#40;&#41;;
            

            }

            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.

            YunusY Offline
            YunusY Offline
            Yunus
            wrote on last edited by
            #5

            @dheerendra Hi, thanks for the answer, but after using Qt::FramelessWindowHint resizability of the window is lost. How can we solve the resize issue ?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved