Results 1 to 4 of 4

Thread: problem with menu entries for mdi windows

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

    Default problem with menu entries for mdi windows

    Hi all!

    I hope this wasn't discussed before, as I haven't found any related posts...

    so my problem is that, i want to make a submenu, where i can list all my currently active mdi windows like in the microsoft office programs, where you can switch between the documents.

    in qt 3, that wasn't a problem since there was a insertItem function, which didn't need a QAction.

    in qt 4 you are only able to add a menu entry via a QAction, which is quite disturbing me.
    i have already looked at the recent files example, which is similar to my problem with the difference, that in this example you assume that there is a maximum count of available entries. (you defined a enum { MAX_RECENTFILES = 9} for example and then defined QAction *recentFiles[MAX_RECENTFILES] in your header file to get the QActions, which I can't do since in the header file I don't know how many active windows there are gonna be)

    BTW: I'm quite new, so chance is high that i missed a very easy way of doing this.

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

    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

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

    y.shan (18th September 2007)

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

    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 

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

    y.shan (18th September 2007)

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

    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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.