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:
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. -
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 forsetAsDockMenu()
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 ofQMenu::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. -
@SGaist and @mpergand,
thanks for the tips! I will go forsetAsDockMenu()
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 ofQMenu::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. -
With that many windows opened, it might be of interest to consider some sort of grouping.