Search code examples
pythonpyqtpyqt5

How to load the PyQt5 UI file from resources?


I want to load the window.ui file from resources_rc.py

I tried:

import resources_rc


class Ui(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui, self).__init__()

        uic.loadUi(':/newPrefix/window.ui', self)

But

OSError: [Errno 22] Invalid argument: ':/newPrefix/window.ui'

PyQt: How do I load a ui file from a resource? didn't help.


Solution

  • Solved. Thanks to musicamante

    stream = QtCore.QFile(":/newPrefix/window.ui")
    stream.open(QtCore.QFile.ReadOnly)
    uic.loadUi(stream, self)
    stream.close()