Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Deactivating close button in MDI child window
Forum Updated to NodeBB v4.3 + New Features

Deactivating close button in MDI child window

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 1.4k 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.
  • M Offline
    M Offline
    Mark531
    wrote on last edited by
    #1

    Hello,

    I've been trying to deactivate the close button in a MDI child window to no avail.

    I've tried this in the constructor of the MDI QDialog:

    self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowCloseButtonHint)
    

    or this:

    self.setWindowFlags(QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMinMaxButtonsHint)
    

    But it didn't change anything. Any hint?

    Thanks,
    Mark

    JonBJ 1 Reply Last reply
    0
    • M Mark531

      Hello,

      I've been trying to deactivate the close button in a MDI child window to no avail.

      I've tried this in the constructor of the MDI QDialog:

      self.setWindowFlags(self.windowFlags() & ~QtCore.Qt.WindowCloseButtonHint)
      

      or this:

      self.setWindowFlags(QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMinMaxButtonsHint)
      

      But it didn't change anything. Any hint?

      Thanks,
      Mark

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Mark531 said in Deactivating close button in MDI child window:

      constructor of the MDI QDialog

      So what exactly is your self?

      A common mistake with MDI sub-windows is failing to understand that the widget you put there is not the one whose flags you want to alter, or call close() on, etc. For a QMdiSubWindow you must understand that is the window you need to operate on, not whatever widget you put into it. Given the widget, you can if necessary access its parent QMdiSubWindow via widget->parentWidget(). Or just something like

      QMdiSubWindow *subWin = mdiArea->addSubWindow(myWidget);
      subWin->setWindowFlags(subWin->windowFlags() & ~QtCore.Qt.WindowCloseButtonHint);
      
      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mark531
        wrote on last edited by
        #3

        @JonB said in Deactivating close button in MDI child window:

        subWin->setWindowFlags(subWin->windowFlags() & ~QtCore.Qt.WindowCloseButtonHint);

        You were right, JonB, I first tried to set the flags in the QDialog constructor. But it seems strange to modify the QMdiSubWindow instead, since the window you call the show method on is the QDialog.
        Anyway, for some reason, I had to reset all flags to make it work:

        my_dialog = MyDialog()
        win = MAIN_WINDOW.mdiArea.addSubWindow(my_dialog)
        # DID NOT WORK
        #win.setWindowFlags(win.windowFlags() & ~QtCore.Qt.WindowCloseButtonHint)
        
        # WORKS
        win.setWindowFlags(QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.WindowMinMaxButtonsHint)
        my_dialog.show()
        
        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