Tag Archives: Pyqt5 Error

Pyqt5 Error: AttributeError: ‘QWidget‘ object has no attribute ‘setCentralWidget‘

problem

AttributeError: 'QWidget' object has no attribute 'setCentralWidget'

reason

We can see setcentralwidget in QT help document that it belongs to the method of qmainwindow class and is defined separately in its class, so it cannot be called directly for its parent class QWidget.

void QMainWindow::setCentralWidget(QWidget *widget)

decided

Write QtWidgets.QWidget() converts QtWidgets.QMainWindow().