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. QDialog with Qt::WindowModal on mac
QtWS25 Last Chance

QDialog with Qt::WindowModal on mac

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 757 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.
  • D Offline
    D Offline
    divide
    wrote on last edited by
    #1

    I need a blocking QDialog (the main app below should be inactive while it is shown) which is able to display sub-windows on top of it. I'm using this QDialog to display VST plugins, which are free to create multiple sub-windows if needed.

    If I set it ApplicationModal, the QDialog is displayed fine, but any sub-windows is shown under the QDialog and therefore cannot be used.
    enter image description here
    ApplicationModal QDialog with no plugin shown
    enter image description here
    ApplicationModal QDialog with a plugin trying to show a sub-window (displayed behind the QDialog and inaccessible)

    If I set it WindowModal, the sub-windows display and works as expected (on top of the QDialog), but the QDialog itself looks weird : it shares its title bar with the main application, and cannot be moved without moving the whole application.
    enter image description here
    WindowModal QDialog with no plugin shown; notice the title bar shared with the main application
    enter image description here
    WindowModal QDialog with a plugin showing a sub-window on top, as expected

    So... I'm kinda stuck here. Is there a way to make a QDialog WindowModal while keeping its own title bar and freedom of movement over the main application, like the ApplicationModal dialog does ?

    I'm using Qt 5.15 on macOS Catalina.

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

      Hi,

      WindowModal and ApplicationModal are two different concepts. AFAIK, on macOS, the style for window modal dialog is to be shown as sheets like you see there.

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        divide
        wrote on last edited by divide
        #3

        Ah, so it's by design and can't be tweaked.
        In that case, do you know if I can show my dialog as non-modal (because it allows plugins to create sub-windows as expected) but somehow block the input events from my main window while this dialog is shown ? So it would act like a modal dialog, but I would handle the blocking/unblocking of the main window manually.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          krypton-001
          wrote last edited by
          #4

          Hi @SGaist I am also facing the same issue as said by @divide

          1 Reply Last reply
          0
          • D divide

            I need a blocking QDialog (the main app below should be inactive while it is shown) which is able to display sub-windows on top of it. I'm using this QDialog to display VST plugins, which are free to create multiple sub-windows if needed.

            If I set it ApplicationModal, the QDialog is displayed fine, but any sub-windows is shown under the QDialog and therefore cannot be used.
            enter image description here
            ApplicationModal QDialog with no plugin shown
            enter image description here
            ApplicationModal QDialog with a plugin trying to show a sub-window (displayed behind the QDialog and inaccessible)

            If I set it WindowModal, the sub-windows display and works as expected (on top of the QDialog), but the QDialog itself looks weird : it shares its title bar with the main application, and cannot be moved without moving the whole application.
            enter image description here
            WindowModal QDialog with no plugin shown; notice the title bar shared with the main application
            enter image description here
            WindowModal QDialog with a plugin showing a sub-window on top, as expected

            So... I'm kinda stuck here. Is there a way to make a QDialog WindowModal while keeping its own title bar and freedom of movement over the main application, like the ApplicationModal dialog does ?

            I'm using Qt 5.15 on macOS Catalina.

            K Offline
            K Offline
            Kevin Hoang
            wrote last edited by
            #5

            @divide said in QDialog with Qt::WindowModal on mac:

            Is there a way to make a QDialog WindowModal while keeping its own title bar and freedom of movement over the main application, like the ApplicationModal dialog does ?

            I'm not completely sure I got your issue right, but have you tried setting it up like this?

            dialog->setWindowModality(Qt::WindowModal);
            dialog->setWindowFlags(Qt::Dialog | Qt::Window);
            
            1 Reply Last reply
            0
            • K Offline
              K Offline
              krypton-001
              wrote last edited by krypton-001
              #6

              Currently, my dialog is something like this (see attached image) i..e no title bar. I want it to be a modal which blocks interaction with it's parent and at the same show title bar. Above solution doesn't works for mac. However below code works fine on ubuntu 22.04. I think this is platform specific issue.

              
              class MyDialog(QtWidgets.QDialog):
                  def __init__(self, parent=None):
                      super().__init__(parent=parent)
                      self.setWindowTitle("My Dialog")
              
                      # Set modality to WindowModal
                      self.setWindowModality(Qt.WindowModal)
              
                      # Set appropriate window flags
                      # self.setWindowFlags(Qt.Dialog | Qt.Window)
              
                      # Set up the layout
                      layout = QtWidgets.QVBoxLayout(self)
                      layout.addWidget(QtWidgets.QLabel("This is a dialog!"))
                      self.setLayout(layout)
              
              
              class MainWindow(QtWidgets.QMainWindow):
                  def __init__(self):
                      super().__init__()
                      self.setWindowTitle("Main Window")
                      self.setGeometry(100, 100, 300, 200)
              
                      # Add a button to the main window
                      self.button = QtWidgets.QPushButton("Show Dialog", self)
                      self.button.setGeometry(100, 80, 100, 40)
                      self.button.clicked.connect(self.show_dialog)
              
                  def show_dialog(self):
                      dialog = MyDialog(self)  # Create dialog with main window as parent
                      dialog.show()  # Show the dialog (exec creates a modal dialog)
              

              Screenshot 2025-04-21 at 4.08.29 PM.png
              This is how it looks on Ubuntu----
              Screenshot 2025-04-21 at 4.12.30 PM.png

              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