14

There are plenty of minor challenges getting PyQt5 and Qt Designer to play nice with PyCharm, but after getting all the small steps in place, I cannot help but wonder if I missed the obvious.

What is the most straightforward way to integrate PyCharm and Qt Designer?

What I did so far:

  • Install Qt Designer
  • Set it up as an external tool
    • Open Settings > Tools > External tools
    • Add a new tool
    • Set the Arguments as $FilePath$ and the Working directory as $Projectpath$
  • Rightclick .ui files in the project explorer and launch Qt Designer from there
  • Set up a File Watcher from Settings, watching for changes to Qt UI Designer Forms and running pyuic5 with the right arguments to generate the matching .py for my .ui

Answers I'm looking for:

  • How can you tighten the loop between Qt Designer and PyCharm? Specifically, can the Qt Designer be opened on a simple double-click from PyCharm or even in a tab in PyCharm?
  • Is there a better overall workflow that achieves the same, that I'm missing here?
Grismar
  • 27,561
  • 4
  • 31
  • 54
  • +1 for these integration ideas. Setting a File Watcher to automatically convert Qt Designer Forms to update the associated Python file is a nice time saver. Weirdly, I needed multiple cracks at setting up the double-click-to-open association as PyCharm wanted to reset the behavior on restart. This latter snag was likely me missing some key setting. Working great now. Cheers. – DaveL17 Mar 04 '21 at 20:34

2 Answers2

16

Step by Step instruction on Integrating QT Designer in Pycharm :

1. Python 3.7 = C:\Users\x\PycharmProjects\Hello\venv\Scripts\python.exe

2. Pip install following:
    a. PyQt5
    b. PyQt5-tools

3. Location of QT designer.exe, which is located in - C:\Users\x\PycharmProjects\Hello\venv\Scripts\designer.exe

4. For QT Designer : File -> Settings -> Tools -> External Tools -> create (+)
    a. Name : QTdesigner
    b. Program : C:\Users\x\PycharmProjects\Hello\venv\Scripts\designer.exe
    c. Arguments : NONE
    d. Working directory : $ProjectFileDir$
    
    OK
    
5. For converting UI file to Py file Pyuic  : File -> Settings -> Tools -> External Tools -> create (+)
    a. Name : PyUIC
    b. Program : C:\Users\x\PycharmProjects\Hello\venv\Scripts\pyuic5.exe
    c. Arguments : -x $FileName$ -o $FileNameWithoutExtension$.py
    d. Working directory : $ProjectFileDir$
    
    OK
    
6. Click Tools -> External Tools -> QTdesigner
    Design your UI and save it as X.ui
    
7. You will have X.ui located in the Project file, 
    a. right click on X.ui
    b. External Tools -> PyUIC
    c. Success 

8. You will be able to see X.py file in the projects folder

9. Run X.py 

10. You should be able to see your GUI Application.
Joker
  • 715
  • 1
  • 14
  • 31
  • 2
    To make PyUIC work with files in subfolders of the project, use arguments `-x $FilePathRelativeToProjectRoot$ -o $FileDirRelativeToProjectRoot$/$FileNameWithoutExtension$.py` – Antimon Aug 14 '21 at 17:15
  • 1
    Can somebody provide a similar solution for Mac? – Ham Dong Kyun Jun 10 '22 at 00:02
8

If you are just looking to open the .ui files in QT Designer, there is a simpler solution.

Go to Settings|File Types and click on "Files Opened in Associated Applications", the go to the Registered Patterns field and add *.ui as a pattern. It will complain that *.ui is already registered to QT Designer. Click OK to reassign the wildcard. Now, when you doubleclick on the .ui file in PyCharm it will open with the associated editor in Windows (which should be Designer).

If PyCharm has already associated the .ui extension with some file type, you can easily override that by selecting the file in the Project browser and selecting File|Associate with File Type... from the menu. Select Open matching files in associated application to have PyCharm open whatever application has been associated with the file type in Windows.

Grismar
  • 27,561
  • 4
  • 31
  • 54
Ian St.John
  • 311
  • 3
  • 6
  • Thanks, but no, that's not what I'm after. The installer I use already creates that association by default and although convenient, it doesn't help creating a closer integration with the IDE. – Grismar Jan 23 '20 at 00:50
  • So, what exactly are you after? Your first bullet says "Specifically, can the Qt Designer be opened on a simple double-click or even in PyCharm". This accomplishes that in a much more simple way then your solution. – Ian St.John Jan 24 '20 at 12:54
  • That's misunderstanding the question, I'm afraid. Your solution doesn't affect what happens when you double-click the .ui file in PyCharm - it would require navigating to the file in another window like Windows File Explorer or another file manager, which defeats the purpose. And with "even in PyCharm", I mean to say "in a tab in PyCharm", if someone knows of a plugin or add-in I may have missed. I've updated the question to avoid further confusion. – Grismar Jan 27 '20 at 12:46
  • I think your previous changes may have interfered with this method. Try again with a fresh PyCharm session. I am using this method right now and can verify that when you doubleclick on the file within PyCharm it will open in Designer. As to the other part of the question, I don't think there is any plugin for PyCharm to open the .ui file in a graphical editor within a tab in PyCharm. – Ian St.John Jan 27 '20 at 13:10
  • I tried with a fresh session, but it didn't work. However, I found how to remedy my situation and will update your answer and then accept it. It's not what I was after ideally, but it does answer my question and it's good enough for my needs. Thanks. – Grismar Jan 28 '20 at 00:40