You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Qt Designer完成的设计与PyCharm中Python3.6.4及PyQt5关联

Hey Tariq, let's get your Qt Designer setup linked with PyCharm and Python 3.6.4 smoothly. Since you've already got PyQt5 installed, here's a step-by-step guide to tie everything together:

Step 1: Configure Python Interpreter in PyCharm
  • Open PyCharm and head to File > Settings (or PyCharm > Preferences if you're on macOS).
  • Navigate to Project: [Your Project Name] > Python Interpreter.
  • Click the gear icon ⚙️ and select Add.
  • Choose System Interpreter, then locate your Python 3.6.4 installation path — based on your pip output, it should be C:\Users\Tariq\AppData\Local\Programs\Python\Python36-32\python.exe.
  • Select this path and click OK to set it as your project's interpreter. This ensures PyCharm uses the exact Python version where you installed PyQt5.
  • Stay in Settings and go to Tools > External Tools.
  • Click the + button to add a new external tool.
  • Fill in these details:
    • Name: Qt Designer
    • Program: Find the designer.exe file in your PyQt5 folder. It’s typically at C:\Users\Tariq\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\PyQt5\Qt\bin\designer.exe
    • Arguments: Leave this blank
    • Working directory: $ProjectFileDir$ (this makes Designer open files relative to your project folder)
  • Click Apply then OK to save. Now you can launch Qt Designer directly from PyCharm via Tools > External Tools > Qt Designer.
Step 3: Convert .ui Files to Python Code

After designing your UI in Qt Designer and saving it as a .ui file, you need to convert it to Python code to use it in your project. Here’s how to set up the converter tool:

  • Go back to Tools > External Tools and click + again.
  • Fill in:
    • Name: PyUIC
    • Program: Your Python 3.6.4 python.exe path (same as before: C:\Users\Tariq\AppData\Local\Programs\Python\Python36-32\python.exe)
    • Arguments: -m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
    • Working directory: $FileDir$
  • Save this tool. Now, right-click your .ui file in PyCharm, go to External Tools > PyUIC, and it’ll generate a corresponding .py file with your UI code.
Step 4: Import and Use the Generated UI Code

In your main Python script, you can import the generated UI class and use it like this:

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow
from your_ui_file_name import Ui_MainWindow  # Replace with your actual UI class name

class MainWindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        # Add your custom functionality here

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec_())

Just make sure the generated .py file is in the same directory as your main script, or adjust the import path if needed.


内容的提问来源于stack exchange,提问作者Tariq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:38:25