Search code examples
pythonpycharmpyqt5qt-designerloadui

I see a blank GUI when I run code from PyCharm


I designed a GUI using QtDesigner and when I run it using Ctrl+R I see a result like I expected.

result

When I import this GUI using ui.loadUi() in PyCharm and run the code,

from PyQt5.QtWidgets import *
from PyQt5.uic import loadUi

class loadUi_example(QMainWindow):

    def __init__(self):
        super().__init__()
        loadUi("view.ui", self)

app = QApplication([])
window = loadUi_example()
window.show()
app.exec_()

I see a blank page.

Blank page

My PyQt version is 5.14.1. And this is my GUI file.


Solution

  • You try to inherit from QMainWindow, instead you should inherit from QWidget:

    class loadUi_example(QWidget):
        def __init__(self):
            super().__init__()
            loadUi("view.ui", self)
    

    This solves your problem.