Oct-03-2017, 03:22 PM
I found the problem by trial and error. It turned out the application closed only when mother is not shown. The reason is that the default behavior is to quit the app when the last window close. As the mother class is used as a daemon, this line must be added to change that behavior:
app.setQuitOnLastWindowClosed(False)
The SubWindow flag is no longer necessary. It end up being a very easy fix, but I still suspect that there is something wrong with my structure. As I was trying to fix the problem I tried to explicitly assign parenting for all widgets, but when I do so they simply don't show. All widgets seems to require "super().__init__()" to be shown.
What am I doing wrong here?
app.setQuitOnLastWindowClosed(False)
The SubWindow flag is no longer necessary. It end up being a very easy fix, but I still suspect that there is something wrong with my structure. As I was trying to fix the problem I tried to explicitly assign parenting for all widgets, but when I do so they simply don't show. All widgets seems to require "super().__init__()" to be shown.
What am I doing wrong here?
#!/usr/bin/python3 import os import sys import time from PyQt5 import QtGui, QtWidgets, QtCore from PyQt5.QtCore import Qt, QThread, QObject, pyqtSignal, pyqtSlot from PyQt5.QtWidgets import QSystemTrayIcon import gui_child, gui_style LOCAL = os.path.dirname(os.path.realpath(__file__)) + '/' ICON_DIR = os.path.dirname(os.path.realpath(__file__)) + '/icons/' class styleDialog(QtWidgets.QDialog): def __init__(self, parent): super().__init__() #super(styleDialog, self).__init__(parent) print("styleDialog parent: " + str(self.parent())) #self.setWindowFlags(Qt.SubWindow) self.background = "" self.ui = gui_style.Ui_Dialog() self.ui.setupUi(self) self.ui.backgroundOpt.clicked.connect(self.pickBackgroundColor) self.exec() def pickBackgroundColor(self): #cw = QtWidgets.QColorDialog() #cw.setParent(self) #color = cw.exec() color = QtWidgets.QColorDialog.getColor() if color: self.background = color.name() #class mother(object): #class mother(QtWidgets.QApplication): class mother(QtWidgets.QMainWindow): def __init__(self, parent=None): #super().__init__() super(mother, self).__init__() print("mother parent: " + str(self.parent())) self.trayIcon = QSystemTrayIcon() self.trayIcon.activated.connect(self.pickColor) self.trayIcon.setIcon(QtGui.QIcon(ICON_DIR + "tray.svg")) self.trayIcon.show() self.children = {} self.children["example"] = child(self) def pickColor(self): style = styleDialog(self) if style.result(): print(style.background) class child(QtWidgets.QWidget): def __init__(self, parent): super().__init__() #super(child, self).__init__(parent) print("child parent: " + str(self.parent())) #self.setWindowFlags(Qt.SubWindow | Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.ui = gui_child.Ui_Form() self.ui.setupUi(self) self.show() if __name__== '__main__': app = QtWidgets.QApplication(sys.argv) app.setQuitOnLastWindowClosed(False) main = mother() sys.exit(app.exec())