Results 1 to 5 of 5

Thread: How to show SubMenu next to MainMenu?

  1. #1
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to show SubMenu next to MainMenu?

    Hi,

    I've added a submenu to the main menu with the following command:

    subMenu = mainMenu->addMenu("Recent files");
    subMenu->addAction(....);
    ...

    The problem is that when I run my application and open subMenu, it's not shown right next to the mainMenu. It might have different positions on the screen and might be not attached to the mainMenu at all.

    How to bind the subMenu to the mainMenu?

    Thanks for any help!!

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show SubMenu next to MainMenu?

    Can u provide some snapshot of how u want it to appear ?
    Also what have u tried ??

  3. #3
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to show SubMenu next to MainMenu?

    The first attached picture is what I have. On the second picture is what I want to have (like it's normally). The first situation happens always when the submenu is shown first time (either when the application has just started or when the content of the submenu has changed). When the same content of the submenu has already been shown once then it's always like on the second picture (but still not perfectly aligned!!).

    (The main menu is a contex menu shown when one of the tray icons is triggered. The submenu on the left is shown when action "Change active profile" is triggered).
    Attached Images Attached Images

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show SubMenu next to MainMenu?

    Can u post the code how you are doing it ?

  5. #5
    Join Date
    Jul 2008
    Posts
    14
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to show SubMenu next to MainMenu?

    The code is below. Some things are missing, but I hope it's clear.. Thanks!

    Qt Code:
    1. void Tray::createMenu()
    2. {
    3. trayIconMenu = new QMenu(this);
    4. fileMenu = trayIconMenu->addMenu("Change active profile");
    5. connect(fileMenu, SIGNAL(aboutToShow()), this, SLOT(activateFileMenu()));
    6.  
    7. trayIcon = new QSystemTrayIcon(this);
    8. trayIcon->setContextMenu(trayIconMenu);
    9. }
    10.  
    11. void Tray::activateFileMenu()
    12. {
    13. fileMenu->clear();
    14. QList<QString> allfiles = files->getAllFiles(); // retrieve file names
    15. fileGroupAction = new QActionGroup(this);
    16. QAction *fileAction;
    17. for (int i = 0; i < allfiles.size(); ++i) { // create a certain number of actions in fileMenu
    18. fileAction = new QAction (files->getIcon(allfiles.at(i)), allfiles.at(i), fileGroupAction);
    19. fileAction->setCheckable(true);
    20. if (files->getImportance(allfiles.at(i))==1)
    21. fileAction->setChecked(true); // one of the files is checked by default
    22. fileMenu->addAction(fileAction);
    23. fileGroupAction->addAction(fileAction);
    24. connect(fileAction, SIGNAL(triggered()), this, SLOT(changeActiveFile()));
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.