Widgets /WidgetBar above of MenuBar



  • Hi,
    I'm looking for a solution to put Widgets above of the QMenuBar.
    I tried

    • use QWidget as root-window
    • add a QVBoxLayout to this widget
    • add a QMainWindow to the layout
    • insert another widget at to the layout index 0, so this widget is on top of the QMainWindow

    It works, but if you put an QMdiArea as centralWidget into the QMainWindow, create some QMdiSubWindows and maximized one of them the behavior is unexpectable:

    The MdiSubWindow maximzed only inside the QMDIArea. It has still it's own titlebar with their controls.
    The controls for maximize, normalize, minimize and close don't get to the menubar of the QMainWindow, because doesn't have the Qt::Window - Flag anymore, because it isn't the root-window.
    see:
    QMdiSubWindowPrivate::setMaximizeMode and
    QMdiSubWindowPrivate::menuBar()

    What else can I do to get widgets above of the QMenuBar?

    Thanks in advance for tips / hints.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Out of curiosity, what are you trying to achieve ? Can you share a picture from that ?



  • OK, I'll give you a code example which shows what I mean.

    #include <QApplication>
    #include <QString>
    #include <QLineEdit>
    #include <QMdiArea>
    #include <QPushButton>
    #include <QVBoxLayout>
    #include <QMenu>
    #include <QMenuBar>
    #include <QToolBar>
    #include <QMainWindow>
    
    
    class CWidgetBar : public QWidget
    {
    public:
      CWidgetBar()
      {
        QHBoxLayout* pLayout = new QHBoxLayout(this);
        for (int i = 1; i < 10; i++)
        {
          pLayout->addWidget(new QPushButton(QString("I %1").arg(i)));
        }
        pLayout->addWidget(new QLineEdit("lineedit"));
        pLayout->addStretch();
      }
    };
    
    int main(int argc, char *argv[])
    {
      QApplication a(argc, argv);
      QWidget* pRootWindow = new QWidget();
      QVBoxLayout* pLayout = new QVBoxLayout(pRootWindow);
    
      //WidgetBar with some buttons...
      CWidgetBar* pWidgetBar = new CWidgetBar();
      pLayout->addWidget(pWidgetBar);
    
      //MainWindow with Menubar plus a MDIArea as centralWidget with three mdisubwindows
      QMainWindow* pMainWindow = new QMainWindow();
      QMenu* pMenu = new QMenu("&File");
      pMenu->addAction("&Open");
      QAction* pCloseAction = pMenu->addAction("&Close");
      QMenuBar* pMenuBar = pMainWindow->menuBar();
      pMenuBar->addMenu(pMenu);
      QToolBar* pToolBar = new QToolBar();
      pToolBar->addAction(pCloseAction);
      pMainWindow->addToolBar(pToolBar);
    
      QMdiArea* pMdiAra = new QMdiArea();
      pMainWindow->setCentralWidget(pMdiAra);
      pMdiAra->addSubWindow(new QPushButton("one"));
      pMdiAra->addSubWindow(new QPushButton("two"));
      pMdiAra->addSubWindow(new QPushButton("three"));
      pLayout->addWidget(pMainWindow);
    
      pRootWindow->show();
      return a.exec();
    }
    

    Please maximize one of the mdisubwindows...



  • Here is the screenshot of the example:
    alt text
    As you can see, the maximized mdisubwindows are maximized only inside the mdiarea still with its own frame and titlebar.

    The expected behavior

    • controls goes to the menubar
    • the title goes to the titlebar of the rootWindow
    • the frame and titlebar of the mdisubwindow disappear

  • Lifetime Qt Champion

    That's not how it works and not something I would expect either.

    The mdi sub-windows will only extend in the mdi area, nothing more.

    The behavior you are looking for, you'll have to implement yourself.



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