0

I use PyCharm and imported an Qt Designer ".ui" with PyQt6:

from PyQt6 import QtWidgets, uic

class Ui(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui, self).__init__()
        uic.loadUi('C:/Users/M/PycharmProjects/2021-12-15_book table/book.ui', self)

        self.pushButton_1 = self.findChild(QtWidgets.QPushButton, "pushButton_1")
        self.pushButton_1.setText('add book')
        self.pushButton_1.clicked.connect(self.add_book)
        #[...]

app = QtWidgets.QApplication(sys.argv)
window = Ui()
app.exec()

PyCharm always shows the errors

  • "Unresolved attribute reference 'setText' or 'Ui' and
  • "Unresolved attribute reference 'connect' or 'Ui' so my understanding is that .findChild does not work.

Do you have an idea how so solve that?

Joe
  • 15
  • 6
  • Does the program work? Note that `loadUi` loads elements dynamically, and PyCharm cannot know that. Those warnings are usually just that, warnings; using `findChild` to avoid them is completely unnecessary, so you can remove it as long as the object names are correct, since `loadUi` automatically creates those attributes at runtime. – musicamante Dec 18 '21 at 16:18
  • The program is working and much longer than the code given above. My issue is, that because PyCharm does not recognise my buttons, labels etc. as such, no programming suggestions by PyCharm are presented. – Joe Dec 18 '21 at 17:29
  • Unfortunately, that's a known problem that cannot be directly "solved": PyCharm cannot know how `loadUi` works and how it creates attributes, since the loading is done at runtime. The only possibilities are to follow what's suggested in the linked answer, or use `pyuic` generated files. – musicamante Dec 18 '21 at 18:51
  • Thank you misicamante, I'll try the suggested solution in the link. Working with an pyuic generated file is not expedient for me because the .ui will grow continuously. – Joe Dec 19 '21 at 13:03

0 Answers0