Qt5 on Mac: List of windows in the Dock menu



  • Hello,
    normally, the list of app windows is shown in the Dock menu for a running app in Mac OS. Here is an example of Firefox:
    alt text
    However, this list is missing for an application, written in Qt. Is there any way to get it working?
    The only thing, I could find, was
    QMenu::setAsDockMenu()
    With this method, however, one would need to keep track of opened/closed windows manually, as far as I understand.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Looks like the right thing to do.

    You can automate the handling using destroyed signal.



  • As with any QMenu, you can listen to the aboutToShow() signal, like that:

    connect(dockMenu,SIGNAL(aboutToShow()),this,SLOT(dockMenuAboutToShow()));
    

    and in the dockMenuAboutToShow() slot:

    QMenu* menu=qobject_cast<QMenu*>(QObject::sender()); 
    if(menu==dockMenu)
       {
       // update the dock menu
    
       }
    


  • @SGaist and @mpergand,
    thanks for the tips! I will go for setAsDockMenu() then. It is interesting that apparently this feature worked automatically at some point in Qt 4, since it works, e.g., in an old version of DjView (v4.5), and they do not have any specific code for that, as far as I can tell.
    A naive question regarding the use of QMenu::aboutToShow(): Would not updating the list each time be noticeably slow, if one has, say, 30+ windows opened. I was thinking about updating the list immediately after a window is opened/closed etc., which seems to be more efficient.



  • A naive question regarding the use of QMenu::aboutToShow(): Would not updating the list each time be noticeably slow

    I open over sixty windows and the dock menu appears in an instant.
    IMHO it's not a issue we should care about with modern computers.


  • Lifetime Qt Champion

    With that many windows opened, it might be of interest to consider some sort of grouping.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.