From 964f974d8ed1e4c11fafe426a118bf1ea5caef04 Mon Sep 17 00:00:00 2001 From: Nils <> Date: Sun, 19 Jul 2020 13:38:18 +0200 Subject: [PATCH] hotfix for new qt release --- template/qtgui/submenus.py | 27 +++++++++++++++------------ template/start.py | 6 +++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/template/qtgui/submenus.py b/template/qtgui/submenus.py index 7e0bb94..ca5b1f9 100644 --- a/template/qtgui/submenus.py +++ b/template/qtgui/submenus.py @@ -25,38 +25,41 @@ import logging; logger = logging.getLogger(__name__); logger.info("import") from typing import Iterable, Callable, Tuple from PyQt5 import QtCore, QtGui, QtWidgets import engine.api as api -from qtgui.constantsAndConfigs import constantsAndConfigs #Client constantsAndConfigs! +from qtgui.constantsAndConfigs import constantsAndConfigs #Client constantsAndConfigs! """ There are two types of submenus in this file. The majority is created in menu.py during start up. Like Clef, KeySig etc. These don't need to ask for any dynamic values. -The other is like SecondaryTempoChangeMenu. In menu.py this is bound with a lambda construct so a +The other is like SecondaryTempoChangeMenu. In menu.py this is bound with a lambda construct so a new instance gets created each time the action is called by the user. Thats why this function has self.__call__ in its init. """ -class Submenu(QtWidgets.QDialog): +class Submenu(QtWidgets.QDialog): def __init__(self, mainWindow, labelString, hasOkCancelButtons=False): - super().__init__(mainWindow) #if you don't set the parent to the main window the whole screen will be the root and the dialog pops up in the middle of it. + super().__init__(mainWindow) #if you don't set the parent to the main window the whole screen will be the root and the dialog pops up in the middle of it. #self.setModal(True) #we don't need this when called with self.exec() instead of self.show() self.layout = QtWidgets.QFormLayout() - #self.layout = QtWidgets.QVBoxLayout() + #self.layout = QtWidgets.QVBoxLayout() self.setLayout(self.layout) label = QtWidgets.QLabel(labelString) #"Choose a clef" or so. self.layout.addWidget(label) #self.setFocus(); #self.grabKeyboard(); #redundant for a proper modal dialog. Leave here for documentation reasons. - - if hasOkCancelButtons: + + if hasOkCancelButtons == 1: #or true self.buttonBox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel) self.buttonBox.accepted.connect(self.process) - self.buttonBox.rejected.connect(self.reject) + self.buttonBox.rejected.connect(self.reject) + elif hasOkCancelButtons == 2: #only cancel. #TODO: unpythonic. + self.buttonBox = QtWidgets.QDialogButtonBox(QtWidgets.QDialogButtonBox.Cancel) + self.buttonBox.rejected.connect(self.reject) else: self.buttonBox = None - + def keyPressEvent(self, event): """Escape closes the dialog by default. @@ -81,7 +84,7 @@ class Submenu(QtWidgets.QDialog): def showEvent(self, event): #TODO: not optimal but better than nothing. super().showEvent(event) - #self.resize(self.layout.geometry().width(), self.layout.geometry().height()) + #self.resize(self.layout.geometry().width(), self.layout.geometry().height()) self.resize(self.childrenRect().height(), self.childrenRect().width()) self.updateGeometry() @@ -91,13 +94,13 @@ class Submenu(QtWidgets.QDialog): def process(self): """Careful! Calling this eats python errors without notice. Make sure your objects exists and your syntax is correct""" - raise NotImplementedError() + raise NotImplementedError() self.done(True) def __call__(self): """This instance can be called like a function""" if self.buttonBox: - self.layout.addWidget(self.buttonBox) + self.layout.addWidget(self.buttonBox) self.setFixedSize(self.layout.geometry().size()) self.exec() #blocks until the dialog gets closed diff --git a/template/start.py b/template/start.py index a59a997..cb8a9c3 100644 --- a/template/start.py +++ b/template/start.py @@ -144,11 +144,11 @@ else: logger.info("PATHS: {}".format(PATHS)) #Construct QAppliction before constantsAndCOnfigs, which has the fontDB -QtGui.QGuiApplication.setDesktopSettingsAware(False) #We need our own font so the user interface stays predictable -QtGui.QGuiApplication.setDesktopFileName(PATHS["desktopfile"]) +#QtGui.QGuiApplication.setDesktopSettingsAware(False) #This will crash with new Qt! qtApp = QApplication(sys.argv) setPaletteAndFont(qtApp) - +QApplication.setStyle(QStyleFactory.create("Fusion")) +setPaletteAndFont(qtApp) def exitWithMessage(message:str): title = f"""{METADATA["name"]} Error"""