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. Making menu bar overlap central widget in QMainWindow

Making menu bar overlap central widget in QMainWindow

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k 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.
  • J Offline
    J Offline
    J.B. Langston
    wrote on last edited by
    #1

    I'm trying to implement an auto-hiding menu bar when my application is in full screen mode. I am using a QMainWindow with a menubar and a central widget. I have implemented this code, and it works after I setMouseTracking(true).

    void MainWindow::mouseMoveEvent(QMouseEvent *event)
    {
        if (isFullScreen()) {
            if (event->pos().y() < menuBar()->sizeHint().height())
                menuBar()->show();
            else
                menuBar()->hide();
        }
    }
    

    The problem is that when the menu bar appears, the central widget moves down to accommodate it and it's jarring. I would rather have the menu bar overlap the central widget so that it doesn't move. Is this possible? If so, how?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Try this in ctor
      ui->menubar->setParent( centralWidget() );
      and add
      void MainWindow::resizeEvent(QResizeEvent *event)
      {
      ui->menubar->resize(width(), ui->menubar->height());
      }

      Tested fast with full screen and seems to work.

      alt text

      J 1 Reply Last reply
      4
      • mrjjM mrjj

        Hi
        Try this in ctor
        ui->menubar->setParent( centralWidget() );
        and add
        void MainWindow::resizeEvent(QResizeEvent *event)
        {
        ui->menubar->resize(width(), ui->menubar->height());
        }

        Tested fast with full screen and seems to work.

        alt text

        J Offline
        J Offline
        J.B. Langston
        wrote on last edited by
        #3

        @mrjj Thanks, this pointed me in the right direction. Here is what I ultimately ended up doing: https://github.com/xaos-project/XaoS/blob/master/src/ui/mainwindow.cpp#L954

        Note that my centralWidget can optionally be a QGLWidget, which complicates things. The menubar won't display over it properly and I also had other problems when the QGLWidget completely filled the screen, such as popup menus not displaying, so I just disabled the autohiding menu if the compile-time USE_OPENGL flag is set.

        1 Reply Last reply
        1

        • Login

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