[Interest] QAction shortcuts in modal dialogs

Rutledge Shawn Shawn.Rutledge at digia.com
Tue Apr 29 12:59:12 CEST 2014


On 19 Apr 2014, at 2:03 AM, John Weeks wrote:

> Our application runs on Macintosh and Windows desktop systems. On Macintosh it is usual to have the menu bar active even when a modal dialog is displayed, and it can be used to cut/copy/paste in editable fields in the dialog.
> 
> Qt, on the other hand, uses the Windows convention of disabling the menu bar when a modal dialog is displayed.

Not the whole menu bar, but most menu items.

> First question: is it possible to override Qt's behavior on a Macintosh?
> 
> In Qt, to make the shortcuts for edit actions work, individual widgets like QLineEdit filter key press events looking for shortcut keystrokes. That makes it really difficult to change those shortcuts, should you choose to do so.
> 
> Second question: Do Qt widgets do it that way because QAction shortcuts don't work in a modal dialog?
> 
> We have a widget that we use in modal dialogs that should have edit actions available. It has a contextual menu, and that works- you can choose Copy from the contextual menu to copy from this widget. But adding a shortcut to that menu doesn't make the shortcut available. I'm guessing that the answer here is that we need to filter the key press events to implement shortcuts in modal dialogs. Is that correct?
> 
> Thank you!

I just recently figured out how to get the menu shortcuts working in QFileDialog:  see QTBUG-17291 and https://codereview.qt-project.org/#change,82404

The basis of it is that the native menu items need to have a "nil" target which means they go to the first responder, which is the native widget that has focus.  Then the OS will intercept the keystrokes that are shortcuts for those menu items, and Qt will not see them, but they will work with the native widgets.  Qt uses a native file dialog, so it's appropriate in that case.  There may be other cases when we need to do that, but none that I know of for sure yet.

But I guess having shortcuts work in Qt widget-based dialogs is a different story anyway.  You can write up a bug about this, and provide an example to demonstrate if possible.


More information about the Interest mailing list