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

Dialog opens on another desktop when opened in MacOS Fullscreen mode



  • Hi,

    As we know, when QMainWindow::showFullScreen is used, the main window opens in a full screen mode on a new virtual desktop in MacOS. While being in that mode, when I first open a dialog, the dialog appears correctly on the virtual desktop where the main menu is. However, if I switch to normal mode by clicking the green traffic light button in MacOs, and then back to full screen, from then on, whenever I open the dialog, it will appear in the main desktop where my virtual desktop is not at.

    Summarized steps:

    1. Open window in Full screen
    2. Open the dialog, dialog will appear on the same desktop as main window. Close dialog by pressing ESQ key
    3. Exit full screen by pressing green traffic light button
    4. Go back to full screen by pressing green traffic light button
    5. Open dialog, notice dialog will open in another desktop

    Here is my simplified code that can reproduce the issue

    // MainWindow.h
    #include <QMainWindow>
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    private:
        QDialog* m_Dlg = nullptr;
    };
    
    // MainWindow.cpp
    #include "MainWindow.h"
    
    #include <QDebug>
    #include <QDialog>
    #include <QFrame>
    #include <QVBoxLayout>
    #include <QPushButton>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
    {
        QPushButton* btn = new QPushButton("Open Dialog");
        connect(btn, &QPushButton::clicked, this, [this]
        {
            if (!m_Dlg)
            {
                m_Dlg = new QDialog(this);
                m_Dlg->setMinimumSize(300, 300);
            }
    
            m_Dlg->show();
        });
    
        QFrame* mainFrame = new QFrame;
        QVBoxLayout* layout = new QVBoxLayout;
        layout->addWidget(btn);
        mainFrame->setLayout(layout);
        setCentralWidget(mainFrame);
    
        showMaximized();
        showFullScreen();
    }
    
    MainWindow::~MainWindow()
    {
    }
    
    // main.cpp
    #include "MainWindow.h"
    
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        return a.exec();
    }
    
    

    Currently, one workaround that I have found is set the dialogs window flag as Qt::Tool. However, in my usage, I don't really need Qt::Tool.
    Is there anyway to properly fix so that dialog always open on the same desktop where the main window is? Thanks in advance

    My system: MacOS 10.15.7 (iMac)
    Qt-5.15.2


  • Lifetime Qt Champion

    Hi,

    How did you install Qt ?



  • @Sivan Hi, I develop on Mac.

    My current project involved dialog boxes (from QDialog and QInputDialog). I use Qt 6.2, macOS current version.
    I can't reproduce your error, be it in my current project or your code.



  • @SGaist I just installed it from the online installer.



  • @artwaw That's good to know. I will try to dig in more to find what fixes it in 6.2 as I might just have to get that patch since I don't have a choice to upgrade to Qt6 for now



  • @artwaw I just gave it a try in 6.2. And I can still see that issue. Are u closing your dialogue using the red traffic light button? If yes, try closing the dialog using ESC key as I mentioned.

    When I close the dialog using the red button, the dialog appears correctly the next time I open. What I noticed is that, when we press the red button to close the dialog, the QCocoaWindow of the dialog gets destroyed, and a new one gets created when we open the dialog again. Whereas, when we press escape, the QCocoaWindow is only hidden and set to visible back when we show the dialog again.

    So far, I noticed the important variables of QCocoaWindow or related subclass's seems to be the same. So still no clue



  • @Sivan Indeed. When closing with ESC the next time the dialog appears it breaks out of fullscreen space.



  • This seems to be how it works in SwiftUI itself. I wrote a simple app to do the same. And the behaviour is the same.
    One way is to set the NSWindow.level = Floating which is equivalent of setting the window flag in qt to Qt::Tool.

    However, I am not sure if there is any other way to achieve this


Log in to reply