Pyside, how to propagate UI changes to parents



  • Hello

    This is my second day with Python and QT so forgive me for a likely newbie question.

    I think my use case is common. I have a pull down menu called "View", in this menu there are QAction items that are checkable for enable and disable MDI windows showing data that is fed from an external HW.

    Showing, hiding the window works well when using the menu only, but there is a close button on the window as well. If closing the window using the close button on the window, the "checked" status in the menu isn't updated.

    I have manage to get this working by providing the MDI window, the associated QAction and toggle the status during closeEvent. If this is a good solution, I cannot say.

    You can get my idea with this code:

    @class MdiWindow(QWidget, Ui_Form):
    def init(self, parent, action):
    super(MdiWindow, self).init(parent)
    self._action = action
    self.setupUi(self)

    def closeEvent(self, event):
        self._action.setChecked(False)
    

    class MainWindow(QMainWindow, Ui_MainWindow):
    _subWindows = [None] * 10

    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.actionData_Window.toggled.connect(self.toggleDataWindow1)
    
    def toggleDataWindow1(self):
        if self.actionData_Window.isChecked():
            window = window(self, self.actionData_Window)
            subWindow = self.mdiArea.addSubWindow(window)
            self._subWindows[0] = subWindow
            subWindow.show()
        else:
            self._subWindows[0].close()
            self._subWindows[0] = None
    

    if name == 'main':
    app = QApplication(sys.argv)
    frame = MainWindow()
    frame.show()
    app.exec_()@

    I've read somewhere that you can use signals as well.

    What is the proper way to solve this here?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.