Stage Manager breaks PyQt5 showMinimized() function
-
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)
-
Hi,
Can you check if you have the same behaviour with PySide6 ?
-
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() -
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.
-
Hi @SGaist,
I've created a bug report here: https://bugreports.qt.io/browse/PYSIDE-2198