How to represent nested widgets in Qt designer in code (PyQt5)?

44 Views Asked by At

After I finished designing the interface with Qt designer, I planned to use Python Pyqt5 in VS code to find parts in the interface for further design, but I did not know how to represent this part in code.

enter image description here

enter image description here

Why does the above code not represent the part I need (account_lineEidt)

Report an error

AttributeError: 'builtin_function_or_method' object has no attribute 'account_Layout'

import sys

from PyQt5.QtWidgets import *
from PyQt5 import uic


class MyWindow(QWidget):

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

    def init_ui(self):
        self.ui = uic.loadUi("./login_interface.ui")

        self.user_name_qwidget = self.ui.layout.widget.account_Layout.account_lineEidt 


if __name__ == '__main__':
    app = QApplication(sys.argv)

    w = MyWindow()
    # 展示窗口
    w.ui.show()

    app.exec()
1

There are 1 best solutions below

0
pengzihao2002 On

I redesigned the interface again and found that the original Dialog had nested a layout, and the layout was nested with other layouts, but the Dialog could have added layouts, which meant I added useless layouts, which caused me to get an error even when I used self.ui.account_lineEdit. So I removed the "layout" and ran it successfully with self.ui.account_lineEdit

Thanks to the experts for their answers!