简体   繁体   English

从 QDialog 到 QWidget 通信,反之亦然

[英]Communicate from QDialog to QWidget and vice versa

I need to show the QDialog when the user presses a button in the QWidget, and to repopulate a QTableWidget that is in the QWidget when the user presses a button in the QDialog.我需要在用户按下 QWidget 中的按钮时显示 QDialog,并在用户按下 QDialog 中的按钮时重新填充 QWidget 中的 QTableWidget。 When I try doing it as bellow it gives me this error: RecursionError: maximum recursion depth exceeded当我尝试这样做时,它给了我这个错误: RecursionError: maximum recursion depth exceeded

# Summary of the Code:

class SettingsWindow(QWidget):
    def __init__(self):
        super().__init__()

        self.inventory_dialog = inventory_dialog()

        self.bmodify_inventario = QPushButton(self.precios)
        self.bmodify_inventario.clicked.connect(self.modify_inventario)


        def modify_inventario(self):

            conn = sqlite3.connect(database)
            c = conn.cursor()
    
            c.execute("SELECT producto FROM inventario")
            list_productos = c.fetchall()

            self.inventory_dialog.producto_input.addItems(
                [i for sub in list_productos for i in sub])

            self.inventory_dialog.deposito_input.addItems(["dep1","dep2", "dep3"])

            conn.close()

            self.inventory_dialog.show()
     

class inventory_dialog(QWidget):
    def __init__(self):
        super().__init__()

        self.SettingsWindow = SettingsWindow()

        self.brepopulate = QPushButton(self)
        self.brepopulate.clicked.connect(self.repopulate)

    def repopulate(self):

        conn = sqlite3.connect(database)

        c = conn.cursor()

        c.execute(
            "SELECT * FROM inventario")
        data = c.fetchall()

        self.SettingsWindow.inventario_table.setRowCount(len(data))

        table_row = 0
        for row in data:
            self.SettingsWindow.inventario_table.setItem(
                table_row, 0, QtWidgets.QTableWidgetItem(row[0]))
            self.SettingsWindow.inventario_table.setItem(
                table_row, 1, QtWidgets.QTableWidgetItem(row[1]))
            self.SettingsWindow.inventario_table.setItem(
                table_row, 2, QtWidgets.QTableWidgetItem(row[2]))
            self.SettingsWindow.inventario_table.setItem(
                table_row, 3, QtWidgets.QTableWidgetItem(row[3]))
            self.SettingsWindow.inventario_table.setItem(
                table_row, 4, QtWidgets.QTableWidgetItem(row[4]))
            self.SettingsWindow.inventario_table.setItem(
                table_row, 5, QtWidgets.QTableWidgetItem(row[5]))
            table_row += 1
           

My Idea for solving this was to repopulate the QTableWidget from the QDialog, but can't get it working.我解决此问题的想法是从 QDialog 重新填充 QTableWidget,但无法使其正常工作。

Everytime SettingsWindow opens inventory_dialog :每次SettingsWindow打开inventory_dialog

 def __init__(self):
        super().__init__()

        self.inventory_dialog = inventory_dialog()

inventory_Dialog opens SettingsWindow ... inventory_Dialog打开SettingsWindow ...

 def __init__(self):
        super().__init__()

        self.SettingsWindow = SettingsWindow()

And it keeps going on forever...而且它会一直持续下去……

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM