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. Help with Isolated QMenu problem
Forum Updated to NodeBB v4.3 + New Features

Help with Isolated QMenu problem

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 865 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.
  • P Offline
    P Offline
    Pt_develop
    wrote on last edited by
    #1

    I'm having a problem placing an isolated QMenu widget as a child widget. I suspect there is something about QMenu that I don't understand and am looking for help. Since QMenu is a widget I assumed that it could be made a child widget of any parent widget; specifically as part of a main window. The documentation gives a very simple example of adding a child widget to a main window (for a QPushButton) as follows:

    @int main(int argc, char *argv[])
    { QApplication a(argc, argv);
    MainWindow w;
    w.resize(400,400);
    w.show();

    QPushButton * push = new QPushButton("button",&w);
    push->move(100,100);
    push->show();
    
    return
    

    }@

    This works but when I try this method with QMenu replacing the QPushButton code with

    @ QMenu * menu1=new QMenu("menu1",&w);
    menu1->move(100,100);
    menu1->show();@

    it does not work. (The documentation says to use the exec function but that didn't work either nor did setting visible or enabled to true work). However if I place the menu in a QMenuBar as follows:

    @ QMenu * menu1=new QMenu("menu1",&w);
    QMenuBar * mbar = new QMenuBar(&w);
    mbar->addMenu(menu1);
    mbar->show();@

    both the menu and the menu bar are visible and enabled.

    I know that mbar becomes the parent of menu1 when using the function addMenu (according to the documentation) so perhaps that is why menu1 becomes visible but can anyone explain why if QMenu is a widget then why cannot it be a child widget of a main window? I'm mystified.

    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