Results 1 to 4 of 4

Thread: problem with menu entries for mdi windows

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: problem with menu entries for mdi windows

    Nut if you don't want a QAction for the menu entry, how will you know when the user clicks one of the entries?

    You have QMenu::addAction(const QString&). You can use its result(the QAction) and connect to its triggered signal. That's when the user clicked your menu entry and you can activate the corresponding window.

    You also have variations on that: addMenu(const QString&), etc

  2. The following user says thank you to marcel for this useful post:

    y.shan (18th September 2007)

  3. #2
    Join Date
    Oct 2006
    Posts
    279
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    6
    Thanked 40 Times in 39 Posts

    Default Re: problem with menu entries for mdi windows

    You must have missed the MDI example.
    Qt Code:
    1. // during construction:
    2. connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowMenu()));
    3.  
    4. void MainWindow::updateWindowMenu()
    5. {
    6. windowMenu->clear();
    7. windowMenu->addAction(closeAct);
    8. windowMenu->addAction(closeAllAct);
    9. windowMenu->addSeparator();
    10. windowMenu->addAction(tileAct);
    11. windowMenu->addAction(cascadeAct);
    12. windowMenu->addSeparator();
    13. windowMenu->addAction(nextAct);
    14. windowMenu->addAction(previousAct);
    15. windowMenu->addAction(separatorAct);
    16.  
    17. QList<QMdiSubWindow *> windows = mdiArea->subWindowList();
    18. separatorAct->setVisible(!windows.isEmpty());
    19.  
    20. for (int i = 0; i < windows.size(); ++i) {
    21. MdiChild *child = qobject_cast<MdiChild *>(windows.at(i)->widget());
    22.  
    23. QString text;
    24. if (i < 9) {
    25. text = tr("&%1 %2").arg(i + 1)
    26. .arg(child->userFriendlyCurrentFile());
    27. } else {
    28. text = tr("%1 %2").arg(i + 1)
    29. .arg(child->userFriendlyCurrentFile());
    30. }
    31. QAction *action = windowMenu->addAction(text);
    32. action->setCheckable(true);
    33. action ->setChecked(child == activeMdiChild());
    34. connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
    35. windowMapper->setMapping(action, windows.at(i));
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to spud for this useful post:

    y.shan (18th September 2007)

  5. #3
    Join Date
    Sep 2007
    Location
    Vienna, Austria
    Posts
    19
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Windows
    Thanks
    10

    Default Re: problem with menu entries for mdi windows

    Quote Originally Posted by spud View Post
    You must have missed the MDI example.
    indeed i missed the example. Though i looked at it, i only looked at the windows menu and couldn't find a windows submenu, hence i thought that wasn't the right example. Now i noticed that the windows are appended to the menu.

    thx for your help

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
  •  
Qt is a trademark of The Qt Company.