I found some tutorials online for earlier versions of Ubuntu but they didn't seem to work on Ubuntu 14.10; either that or I was doing it the wrong way.

I want to use Qt Designer to design a GUI, use PyQt to covert it to .py, then use it in Python.

What packages do I need to install to do this?

up vote 12 down vote accepted

All the tools you need are included in Ubuntu repositories. You must install the package qtcreator, which has an integrated QtDesigner, and the package pyqt5-dev-tools, which provides pyuic5, a utility that generates Python code from .ui files.

sudo apt-get install qtcreator pyqt5-dev-tools
  • 2
    Small note for those that follow. The module is found by importing like import PyQt5 . – Ross Rogers Apr 12 '16 at 16:28

Run these in a Terminal:

sudo apt-get install python3-pyqt5

sudo apt-get install qttools5-dev-tools

sudo apt-get install qtcreator pyqt5-dev-tools

Run PyQt5 Designer, located at:

/usr/bin/designer

Run PyQt5 User Interface Compiler (PYUIC5) to convert .ui to .py

pyuic5 gui.ui -o gui.py

Run PyQt5 Resource Compiler (PYRCC5) to convert .qrc to .py

pyrcc5 images.qrc -o images_rc.py

  1. Install python3.
  2. Install sip.
  3. Install python3-pip.
  4. Run the command: pip3 install pyqt5
  • is it pip or sip? – Hafiz Shehbaz Ali Mar 25 '17 at 6:02
  • 1
    @HafizShehbazAli It may be that sip-dev was intended instead of sip, but pip doesn't make sense here. The Python 3 version of the pip package manager is provided by the python3-pip package which is already separately listed. SIP is related to PyQt. mayur: Can you edit this to include an explanation of how to "install sip" and why? – Eliah Kagan Nov 12 '17 at 17:14

Well, I documented the steps for Installing pyqt5 with qt designer and code generation here: https://gist.github.com/ujjwal96/1dcd57542bdaf3c9d1b0dd526ccd44ff

With this you can generate the code from Qt Designer itself.

Installation

pip3 install --user pyqt5  
sudo apt-get install python3-pyqt5  
sudo apt-get install pyqt5-dev-tools
sudo apt-get install qttools5-dev-tools

Configuring to run from terminal

$ qtchooser -run-tool=designer -qt=5

OR

Write the following in /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf

/usr/lib/x86_64-linux-gnu/qt5/bin
/usr/lib/x86_64-linux-gnu

Code Generation

Create uic.py file.

#!/usr/bin/python3

import subprocess
import sys

child = subprocess.Popen(['pyuic5' ,'-x',sys.argv[1]],stdout=subprocess.PIPE)

print(str(child.communicate()[0],encoding='utf-8'))


$ chmod +x uic.py

Create a symlink:

$ sudo ln uic.py "/usr/lib/x86_64-linux-gnu/qt5/bin/uic"

Desktop Entry

[Desktop Entry]
Name=Qt5 Designer
Icon=designer
Exec=/usr/lib/x86_64-linux-gnu/qt5/bin/designer
Type=Application
Categories=Application
Terminal=false
StartupNotify=true
Actions=NewWindow

Name[en_US]=Qt5 Designer

[Desktop Action NewWindow]
Name=Open a New Window
Exec=/usr/lib/x86_64-linux-gnu/qt5/bin/designer

save in ~/.local/share/application with .desktop extension

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.