Nominate our 2022 Qt Champions!

Qt Mac OSX: Few menu items are disabled after QFileDialog

  • Hello. Sorry if this is not the right place to post this. I am not sure if this is a bug.

    I use QFileDialog static functions (getOpenFile and getSaveFile) in my Qt app. It works perfectly on Linux and Windows.

    On Mac however, after running the dialog, the menu items Cut, Copy, Paste and Select All are disabled. Putting in setEnabled(true) on the actions after QFileDialog returns didn't work, the menu items stay disabled. I also tried menuBar()->update() with no success.

    The one thing that does help is DontUseNativeDialogs. When I use it, the menu items are unaffected after. Still, I would like to use native dialogs on Mac (the non-native dialogs look very out of place).

    Important to point out that the same QFileDialog works fine on Linux and Windows and doesn't mess up the menu. I've tried Qt 5.4.0 and 5.4.1 on Mac and both have this problem.

    Could this be a bug? I would be surprised that I discovered it, considering that it seems like something that would be noticed right away. As such, I put it as more likely that it's something wrong that I am doing. Any ideas? I am looking for any solutions. If I become desperate, I will try to regenerate the entire menu bar after using QFileDialog (but this shouldn't be necessary!).

    BTW, I found an old bug, QTBUG-20156, but it seems like that affects Mac OSX 10.4. My problems are occurring on 10.8 and 10.10 (latest, Yosemite).


  • Lifetime Qt Champion


    Since you seem to hit a similar bug, would you consider opening a new report providing a minimal compilable example that reproduce the behavior ? Linking to the old one would also be good.

  • I wasn't able to create a minimal example. When I set up a trivial window with a menu and add a Copy action, it doesn't disable when I open a QFileDialog.

    I tried to be careful and do it in the same way like in my app, but of course it could be any number of things (it is an app with a 50 or so menu items, and a number of widgets and I have seen enough odd bugs in my life to know that anything can trigger a bug, especially my stupidity or say, gamma rays).

    I did have success with a small discovery! If I call setMenuRole(QAction::NoRole) on my "Copy", "Paste", "Cut" and "Select All", then they won't disable after calling QFileDialog. Unfortunately, in this case the "Copy", "Paste", "Cut" and "Select All" actions don't work in the file dialog, but this is much preferred over them not working in the app.

    I understand that Qt does a lot of magic with menus on the Mac (considering how they work with the global menu and everything), so this may be a useful pointer at the source of the problem. Perhaps I will look into Qt Mac source (if it is not too hard to get into it).

    In the meantime, if anyone else runs across this, please post any information you discover.

  • Lifetime Qt Champion

    Speaking of gamma rays, you could try to take a look at your application with KDAB's Gamma Ray you might find with it if you have some funny signal/slot/even loop stuff going on.

    The cocoa platform plugin would be the place to start digging if you want to get the gory details.

Log in to reply