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. QMenuBar: menu is hidden when moving window to another monitor
Forum Updated to NodeBB v4.3 + New Features

QMenuBar: menu is hidden when moving window to another monitor

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.3k Views 2 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.
  • Z Offline
    Z Offline
    zulu
    wrote on last edited by
    #1

    Hi ALL,

    I am using MDI interface and trying to add QMenuBar and QToolBar to MDI Child window.
    As the Qt designer allow to add menu and tool bar only to QMainWindow I am doing this in the code bacause QMdiSubWindow is inherited from QtWidget.
    Here is the code.

    resize(300, 300);
    QWidget* widget = new QWidget(this);
    widget->show();

    QMenuBar *menuBar = new QMenuBar(widget);
    QMenu *fileMenu = new QMenu("File");
    menuBar->addMenu(fileMenu);
    fileMenu->addAction("Save");
    fileMenu->addAction("Exit");
    QMenu *actionMenu = new QMenu("Action");
    menuBar->addMenu(actionMenu);
    actionMenu->addAction("Start");
    actionMenu->addAction("Finish");

    menuBar->move(0, 0);

    QToolBar* toolbar = new QToolBar(widget);

    QIcon icon1("RED.ico");
    toolbar->addAction(icon1,"OPEN");
    QIcon icon2("YELLOW.ico");
    toolbar->addAction(icon2,"CLOSE");

    QRect rect = menuBar->frameGeometry(); //getting the height of the menu strip to place tool bar below
    int height = rect.height();
    toolbar->move(0, height);

    setWidget(widget);

    I am adding two icons to the tool bar.
    Everything is looking fine but there is one problem.
    I have two monitors. First with 2560 x 1440 resolution and second 1910 x 1080.
    When the program launched on the first it looks fine. When I move it to the second it also looks fine.
    When the program is launched on the second monitor it looks fine but when I move it to the first monitor i see this:

    0_1545321010831_qt_demo_bad.jpg

    But on another monitor i see this:

    0_1545321034459_qt_demo_good.jpg
    Menu of the child window is hidden. That only happens when program starts on the LowResolution monitor (second) and moved to HIgh resolution monitor (first).
    I am not sure if i placed menu and tool bar correctly.
    What is the problem?
    thanks.

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

      Hi
      I think its due to you forgot the layout as shown in the sample
      https://forum.qt.io/topic/97803/qmdisubwindow-is-it-possible-to-add-menu-strip/3

      1 Reply Last reply
      3
      • Z zulu

        Hi ALL,

        I am using MDI interface and trying to add QMenuBar and QToolBar to MDI Child window.
        As the Qt designer allow to add menu and tool bar only to QMainWindow I am doing this in the code bacause QMdiSubWindow is inherited from QtWidget.
        Here is the code.

        resize(300, 300);
        QWidget* widget = new QWidget(this);
        widget->show();

        QMenuBar *menuBar = new QMenuBar(widget);
        QMenu *fileMenu = new QMenu("File");
        menuBar->addMenu(fileMenu);
        fileMenu->addAction("Save");
        fileMenu->addAction("Exit");
        QMenu *actionMenu = new QMenu("Action");
        menuBar->addMenu(actionMenu);
        actionMenu->addAction("Start");
        actionMenu->addAction("Finish");

        menuBar->move(0, 0);

        QToolBar* toolbar = new QToolBar(widget);

        QIcon icon1("RED.ico");
        toolbar->addAction(icon1,"OPEN");
        QIcon icon2("YELLOW.ico");
        toolbar->addAction(icon2,"CLOSE");

        QRect rect = menuBar->frameGeometry(); //getting the height of the menu strip to place tool bar below
        int height = rect.height();
        toolbar->move(0, height);

        setWidget(widget);

        I am adding two icons to the tool bar.
        Everything is looking fine but there is one problem.
        I have two monitors. First with 2560 x 1440 resolution and second 1910 x 1080.
        When the program launched on the first it looks fine. When I move it to the second it also looks fine.
        When the program is launched on the second monitor it looks fine but when I move it to the first monitor i see this:

        0_1545321010831_qt_demo_bad.jpg

        But on another monitor i see this:

        0_1545321034459_qt_demo_good.jpg
        Menu of the child window is hidden. That only happens when program starts on the LowResolution monitor (second) and moved to HIgh resolution monitor (first).
        I am not sure if i placed menu and tool bar correctly.
        What is the problem?
        thanks.

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @zulu
        can't tell you exactly what is happening without proper debugging but anyway i think you want to achieve the following:

        MyMdiSubWindow::MyMdiSubWindow(QWidget* parent)
            : QMdiSubWindow(parent)
        {
            QMenuBar *menuBar = new QMenuBar(widget);
                // ...
        
            QToolBar* toolBar = new QToolBar(widget);
                 // ...
        
            QVBoxLayout* layout = new QVBoxLayout;
                 layout->addWidget( menuBar );
                 layout->addWidget( toolBar );
                 layout->addWidget( contentWidget, 1000 ); 
        
            QWidget* widget = new QWidget( this );
                 widget->setLayout( layout );
            setWidget(widget);
        }
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        4
        • Z Offline
          Z Offline
          zulu
          wrote on last edited by
          #4

          Yes i have removed the QVBoxLayout beacuse I didn't get how to use it properly.
          When i add menu and toolbar to it the toolbar is in the middle of the window.
          So i guess i need to add an area below the toolbox. (Client area).
          In this line we add something but i can't get what do we actually add:

          layout->addWidget( contentWidget, 1000 );

          Could you explain?

          @raven-worx said in QMenuBar: menu is hidden when moving window to another monitor:

          contentWidget

          raven-worxR 1 Reply Last reply
          0
          • Z zulu

            Yes i have removed the QVBoxLayout beacuse I didn't get how to use it properly.
            When i add menu and toolbar to it the toolbar is in the middle of the window.
            So i guess i need to add an area below the toolbox. (Client area).
            In this line we add something but i can't get what do we actually add:

            layout->addWidget( contentWidget, 1000 );

            Could you explain?

            @raven-worx said in QMenuBar: menu is hidden when moving window to another monitor:

            contentWidget

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @zulu said in QMenuBar: menu is hidden when moving window to another monitor:

            Could you explain?

            it just makes sure that the content (added with a stretch of 1000) "pushes" the other widgets in the layout to the top

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              zulu
              wrote on last edited by
              #6

              But what is contentWidget?
              I don't have this variable in y context?

              raven-worxR 1 Reply Last reply
              0
              • Z zulu

                But what is contentWidget?
                I don't have this variable in y context?

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                @zulu
                i assumed there will be later on.
                If not, remove this line, or simply insert a empty widget (new QWidget)

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                2
                • Z Offline
                  Z Offline
                  zulu
                  wrote on last edited by
                  #8

                  Sorry for a long break.
                  After holidays i have returned to development.
                  I have added new QTwidget line and everything is ok now.
                  Thanks a lot

                  1 Reply Last reply
                  2

                  • Login

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