Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Best way to implement Window menu



  • My program has a Window menu that lists out all of the open windows: each action, when triggered, should raise the selected window and give it keyboard focus. <code>raise()</code> is easy enough, since it's a slot, but it doesn't give the window the input focus. <code>activateWindow()</code> isn't a slot. What is the best way of implementing this behavior? Is there a slot that does this that I'm missing?



  • You could derive your windows from your own subclass. In that you can add a new slot that calls raise() and activateWindow(). The other solution would be to add a slot to your main class and do it there. You need to add some bookkeeping about the windows, though.



  • Thanks—I went with your first suggestion, which of course works fine. I find it odd that activateWindow() isn't a slot: do you happen to know the design rationale behind that?



  • Sorry, I have no clue, why this is not a slot. You might want to file a suggestion on the "public bugtracker":https://bugreports.qt.nokia.com/. So at least it will be reconsidered for the upcoming Qt 5 release later this year.


Log in to reply