Installation[edit | edit source]

To install Qt Designer without having to download all the GBs of data (on Windows) simply go into Anaconda and type the following :

pip install pyqt5-installer
pip install pyqt5
pip install pyqt5-tools

Once the installations are finished go into the pyqt5 site-packages folder, for me the address for this was :


And in there you will find the designer.exe application file. Click on that and Qt Designer will start.

Creating our first basic app[edit | edit source]

Now that you are in Qt lets select the template 'Dialog with Buttons Bottom'. 

You can change your UI in here, but for now lets just change the Window Title and then save our ui as  dialog.ui.

Converting .ui to .py[edit | edit source]

Go back into Anaconda and go to where our ui file is that we just created. Then enter :

pyuic5 dialog.ui >

This will convert our ui file into a py file that we can actually use.

Next we can make some minor changes  such as the generated class name so it makes more sense to us.

The final code should look something like this :

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'magicCounter_UI.ui'
# Created by: PyQt5 UI code generator 5.11.3
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.resize(400, 300)
        self.buttonBox = QtWidgets.QDialogButtonBox(Dialog)
        self.buttonBox.setGeometry(QtCore.QRect(30, 240, 341, 32))


    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Magic: The Gathering Life Counter"))

Then we create another .py file and call it :

import sys
from PyQt5.QtWidgets import QDialog, QApplication
from dialog import Ui_Dialog

class AppWindow(QDialog):
    def __init__(self):
        self.ui = Ui_Dialog()

app = QApplication(sys.argv)
w = AppWindow()

Then we run our file and we should get our window looking something like this :


If you are using the template of a MainWindow then your file will need to look slightly different, otherwise you will get this pesky

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

error. So instead we need to implement it with QMainWIndow.

To do this, your PyQt5.QtWidgets import statement should look something like this :

from PyQt5.QtWidgets import QApplication, QMainWindow

and then down the bottom where you declared your app and window variables, change and add the following :

app = QApplication(sys.argv)
window = QMainWindow()

ui = Ui_MainWindow()

Now when you run the file, it should load successfully.

References[edit | edit source]

Design Simple Dialog Using PyQt5 Designer Tool - Codementor Community

AttributeError: QDialog object has no attribute setCentralWidget - Stackoverflow

Community content is available under CC-BY-SA unless otherwise noted.