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. Stage Manager breaks PyQt5 showMinimized() function
Forum Updated to NodeBB v4.3 + New Features

Stage Manager breaks PyQt5 showMinimized() function

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 2 Posters 769 Views 2 Watching
  • 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.
  • Ard_FlamingoA Offline
    Ard_FlamingoA Offline
    Ard_Flamingo
    wrote on last edited by Ard_Flamingo
    #1

    I've been working on adding a minimize function to my app using the showMinimized() function. It works fine, but after you minimize once, it just won't work anymore. For some odd reason, when I turn off Stage Manager, it always works and you can minimize many times, but when Stage Manager is on, you can only minimize the window once, afterwards the button/shortcut doesn't do anything. One thing that does seem to *work however, is if I enter fullscreen (after minimizing once, when it doesn't work anymore), minimizing will actually work. It seems like it's a problem with Stage Manager, has anyone else had this problem?

    (*it works only once, again, not an infinite amount of times)

    import os.path
    import sys
    from sys import platform
    from PyQt5.QtWidgets import *
    #from PyQt5.Qt import Qt
    from PyQt5.QtGui import QWindow
    from MainWindow import *
    
    if platform == 'darwin':
        from Foundation import NSBundle
        bundle = NSBundle.mainBundle()
        if bundle:
            info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
            if info and info['CFBundleName'] == 'Python':
                info['CFBundleName'] = "Neo Text"
    
    
    class MainWindow(QMainWindow):
        def __init__(self):
            super(QMainWindow, self).__init__()
            self.ui = Ui_MainWindow()
            self.ui.setupUi(self)
            self.path = None
    
            self.ui.actionNew.triggered.connect(lambda: self.newFile())
            self.ui.actionOpen.triggered.connect(lambda: self.openFile())
            self.ui.actionSave.triggered.connect(lambda: self.fileSave())
            self.ui.actionSave_As.triggered.connect(lambda: self.fileSaveAs())
    
            self.ui.actionCut.triggered.connect(lambda: self.ui.plainTextEdit.cut())
            self.ui.actionCopy.triggered.connect(lambda: self.ui.plainTextEdit.copy())
            self.ui.actionPaste.triggered.connect(lambda: self.ui.plainTextEdit.paste())
    
            self.ui.actionMinimize.triggered.connect(lambda: self.showMinimized())
    
            self.updateTitle()
            self.show()
    
        def newFile(self):
            self.path = None
            self.ui.plainTextEdit.clear()
            self.fileSaveAs()
            self.updateTitle()
    
        def openFile(self):
            path, _ = QFileDialog.getOpenFileName(self, "Open File", "", "Text documents (*.txt);All files (*.*)")
    
            if path:
    
                try:
                    with open(path, 'r') as f:
                        text = f.read()
    
                except Exception as e:
                    pass
    
                else:
                    self.path = path
                    self.ui.plainTextEdit.setPlainText(text)
                    self.updateTitle()
    
        def fileSave(self):
            if self.path is None:
                return self.fileSaveAs()
    
            self.saveToPath(self.path)
    
        def fileSaveAs(self):
            path, _ = QFileDialog.getSaveFileName(self, "Save File", "", "Text documents (*.txt);All files (*.*)")
    
            if not path:
                return
    
            self.saveToPath(path)
    
        def saveToPath(self, path):
            text = self.ui.plainTextEdit.toPlainText()
    
            try:
                with open(path, 'w') as f:
                    f.write(text)
    
            except Exception as e:
                pass
    
            else:
                self.path = path
                self.updateTitle()
    
        def updateTitle(self):
            self.setWindowTitle("%s - Neo Text" % (os.path.basename(self.path) if self.path else "Untitled"))
    
    
    app = QApplication(sys.argv)
    app.setApplicationName("Neo Text")
    
    window = MainWindow()
    
    sys.exit(app.exec_())
    
    

    (Line #34 is what you want)

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

      Hi,

      Can you check if you have the same behaviour with PySide6 ?

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

      Ard_FlamingoA 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Can you check if you have the same behaviour with PySide6 ?

        Ard_FlamingoA Offline
        Ard_FlamingoA Offline
        Ard_Flamingo
        wrote on last edited by
        #3

        Hi @SGaist

        Unfortunately I am getting the same behaviour in PySide6. Could it possibly be an issue with Qt?

        Here's the PySide6 code I've tried:

        import sys
        from PyQt6.QtWidgets import *
        
        app = QApplication(sys.argv)
        
        window = QMainWindow()
        menubar = window.menuBar()
        menubar.setNativeMenuBar(False)
        window.show()
        minimizeAction = menubar.addAction('Minimize')
        minimizeAction.triggered.connect(lambda: window.showMinimized())
        
        app.exec()
        
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Possibly as this is a new macOS feature which may have unexpected consequences.

          Since you can reliably reproduce it, you should go to the bug report system to see if it's something already known and if not please open a new issue with your code example.

          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
          1
          • Ard_FlamingoA Offline
            Ard_FlamingoA Offline
            Ard_Flamingo
            wrote on last edited by
            #5

            Hi @SGaist,

            I've created a bug report here: https://bugreports.qt.io/browse/PYSIDE-2198

            1 Reply Last reply
            2

            • Login

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