def event(self, ev): """Catch system events.""" if ev.type() == QEvent.PaletteChange: # detect theme switches style = interface_style() # light or dark if style is not None: QIcon.setThemeName(style) else: QIcon.setThemeName("light") # fallback return super().event(ev)
def resource_path(path): if getattr(sys, 'frozen', False): basedir = sys._MEIPASS else: basedir = os.path.dirname(__file__) return os.path.join(basedir, path) if __name__ == '__main__': print(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'icons')) d = [] d.extend([os.path.join(d, '.icons') for d in get_xdr_data_home()]) d.extend([os.path.join(d, 'icons') for d in get_xdr_data_dirs()]) d.extend([resource_path('icons')]) QIcon.setThemeSearchPaths(d) QIcon.setThemeName('default') app = QApplication(sys.argv) app.setApplicationName(APPLICATION_NAME) app.setOrganizationName(ORGANIZATION_NAME) # QSettings.setDefaultFormat(QSettings.IniFormat) w = MainWindow() w.new_document() w.show() sys.exit(app.exec_())
import sys import platform from PySide6.QtGui import QGuiApplication, QIcon from PySide6.QtCore import QSettings, QUrl from PySide6.QtQml import QQmlApplicationEngine, QQmlContext from PySide6.QtQuickControls2 import QQuickStyle import rc_gallery if __name__ == "__main__": QGuiApplication.setApplicationName("Gallery") QGuiApplication.setOrganizationName("QtProject") app = QGuiApplication() QIcon.setThemeName("gallery") settings = QSettings() if not os.environ.get("QT_QUICK_CONTROLS_STYLE"): QQuickStyle.setStyle(settings.value("style", str)) engine = QQmlApplicationEngine() built_in_styles = ["Basic", "Fusion", "Imagine", "Material", "Universal"] if platform.system() == "Darwin": built_in_styles.append("macOS") elif platform.system() == "Windows": built_in_styles.append("Windows") engine.rootContext().setContextProperty("builtInStyles", built_in_styles) engine.load(":/gallery.qml")