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. Expanded client area in QMainWindow

Expanded client area in QMainWindow

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 89 Views
  • 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.
  • H Offline
    H Offline
    hexo
    wrote last edited by hexo
    #1

    I want my application to occupy the entire available screen (including the titlebar area). Normally I am able to achive this using ExpandedClientAreaHint and NoTitleBarBackgroundHint window flags like the following minimal example:

    
    #include <QApplication>
    #include <QPainter>
    #include <QMainWindow>
    
    class MyWidget : public QWidget
    {
    public:
        MyWidget(QWidget* parent=nullptr) : QWidget(parent) {}
    
        void paintEvent(QPaintEvent* event) override
        {
            QPainter painter(this);
            painter.fillRect(rect(), Qt::blue);
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        MyWidget* my_widget = new MyWidget();
    
        my_widget->setWindowFlag(Qt::ExpandedClientAreaHint, true);
        my_widget->setWindowFlag(Qt::NoTitleBarBackgroundHint, true);
        my_widget->show();
    
        return a.exec();
    }
    
    

    Which looks like this:
    Screenshot 2025-05-09 at 5.09.40 PM.png

    However, when I use a QMainWindow as the top level window of the application, the titlebar background is still rendered. Here is a minimal example:

    
    #include <QApplication>
    #include <QPainter>
    #include <QMainWindow>
    
    class MyWidget : public QWidget
    {
    public:
        MyWidget(QWidget* parent=nullptr) : QWidget(parent) {}
    
        void paintEvent(QPaintEvent* event) override
        {
            QPainter painter(this);
            painter.fillRect(rect(), Qt::blue);
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        MyWidget* my_widget = new MyWidget();
    
        QMainWindow window;
        window.setWindowFlag(Qt::ExpandedClientAreaHint, true);
        window.setWindowFlag(Qt::NoTitleBarBackgroundHint, true);
        window.setCentralWidget(my_widget);
        window.show();
    
        return a.exec();
    }
    

    and here is how it looks:

    Screenshot 2025-05-09 at 5.10.22 PM.png

    How can I achieve the original look while using QMainWindow?

    This is on Qt 6.9.0 on MacOS.

    Pl45m4P 1 Reply Last reply
    0
    • H hexo

      I want my application to occupy the entire available screen (including the titlebar area). Normally I am able to achive this using ExpandedClientAreaHint and NoTitleBarBackgroundHint window flags like the following minimal example:

      
      #include <QApplication>
      #include <QPainter>
      #include <QMainWindow>
      
      class MyWidget : public QWidget
      {
      public:
          MyWidget(QWidget* parent=nullptr) : QWidget(parent) {}
      
          void paintEvent(QPaintEvent* event) override
          {
              QPainter painter(this);
              painter.fillRect(rect(), Qt::blue);
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          MyWidget* my_widget = new MyWidget();
      
          my_widget->setWindowFlag(Qt::ExpandedClientAreaHint, true);
          my_widget->setWindowFlag(Qt::NoTitleBarBackgroundHint, true);
          my_widget->show();
      
          return a.exec();
      }
      
      

      Which looks like this:
      Screenshot 2025-05-09 at 5.09.40 PM.png

      However, when I use a QMainWindow as the top level window of the application, the titlebar background is still rendered. Here is a minimal example:

      
      #include <QApplication>
      #include <QPainter>
      #include <QMainWindow>
      
      class MyWidget : public QWidget
      {
      public:
          MyWidget(QWidget* parent=nullptr) : QWidget(parent) {}
      
          void paintEvent(QPaintEvent* event) override
          {
              QPainter painter(this);
              painter.fillRect(rect(), Qt::blue);
          }
      };
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          MyWidget* my_widget = new MyWidget();
      
          QMainWindow window;
          window.setWindowFlag(Qt::ExpandedClientAreaHint, true);
          window.setWindowFlag(Qt::NoTitleBarBackgroundHint, true);
          window.setCentralWidget(my_widget);
          window.show();
      
          return a.exec();
      }
      

      and here is how it looks:

      Screenshot 2025-05-09 at 5.10.22 PM.png

      How can I achieve the original look while using QMainWindow?

      This is on Qt 6.9.0 on MacOS.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote last edited by
      #2

      @hexo said in Expanded client area in QMainWindow:

      How can I achieve the original look while using QMainWindow?

      What's the point for QMainWindow then if you don't need title bars and so on?
      QMainWindow is just an enhanced version of QWidget.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hexo
        wrote last edited by hexo
        #3

        @Pl45m4 I want to have MacOS's integrated menubar (the one that is integrated with the system menubar) but I don't want the application titlebar.

        S 1 Reply Last reply
        0
        • H hexo

          @Pl45m4 I want to have MacOS's integrated menubar (the one that is integrated with the system menubar) but I don't want the application titlebar.

          S Offline
          S Offline
          StudentScripter
          wrote last edited by
          #4

          @hexo Not really possible with qt... i tried too for way to long. There is a frameless window example that goes into this direction but than u loose the ability for good docking of the window.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hexo
            wrote last edited by
            #5

            @StudentScripter I used to be able to do this using custom macos-specific code (see https://github.com/ahrm/sioyek/pull/1015) but it has stopped working in recent Qt versions (I think after 6.8 but I am not 100% sure).

            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