Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Dialog opens on another desktop when opened in MacOS Fullscreen mode

Dialog opens on another desktop when opened in MacOS Fullscreen mode

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 692 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sivan
    wrote on last edited by Sivan
    #1

    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

    artwawA 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How did you install Qt ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply
      0
      • S Sivan

        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

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by
        #3

        @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.

        For more information please re-read.

        Kind Regards,
        Artur

        S 2 Replies Last reply
        0
        • SGaistS SGaist

          Hi,

          How did you install Qt ?

          S Offline
          S Offline
          Sivan
          wrote on last edited by
          #4

          @SGaist I just installed it from the online installer.

          1 Reply Last reply
          0
          • artwawA artwaw

            @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.

            S Offline
            S Offline
            Sivan
            wrote on last edited by
            #5

            @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

            1 Reply Last reply
            0
            • artwawA artwaw

              @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.

              S Offline
              S Offline
              Sivan
              wrote on last edited by Sivan
              #6

              @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

              artwawA 1 Reply Last reply
              0
              • S Sivan

                @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

                artwawA Offline
                artwawA Offline
                artwaw
                wrote on last edited by
                #7

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

                For more information please re-read.

                Kind Regards,
                Artur

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sivan
                  wrote on last edited by
                  #8

                  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

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved