安装pyside6
pip3 install pyside6
安装vscode
不多说,直接去官网下也好,linux用命令安装也好,都是极为简单
在vscode中安装Qt for Python插件
配置插件按下图找到插件小齿轮,点击“扩展设置”
需要配置的地方有五处分别如下图
-
第一处
"qtForPython.designer.path": "此处输入你之前安装的pyside6 designer的路径",
-
第二处
"qtForPython.rcc.path": "此处输入pyside6-rcc的路径",
-
第三处
"qtForPython.uic.path": "此处输入pyside6-uic的路径",
-
第四处
#输入的内容如下
-o ${fileDirname}${pathSeparator}rc_${fileBasenameNoExtension}.py
-
第五处
#输入的内容如下
-o ${fileDirname}${pathSeparator}Ui_${fileBasenameNoExtension}.py
最终配置好的文件内容:
{
"pyqt-integration.linguist.cmd": "/home/lei/.local/bin/pyside6-linguist",
"qtForPython.designer.path": "/home/lei/.local/lib/python3.10/site-packages/PySide6/designer",
"qtForPython.rcc.path": "/home/lei/.local/bin/pyside6-rcc",
"qtForPython.uic.path": "/home/lei/.local/bin/pyside6-uic",
"qtForPython.uic.args": [
"-o ${fileDirname}${pathSeparator}Ui_${fileBasenameNoExtension}.py"
],
"qtForPython.rcc.args": [
"-o ${fileDirname}${pathSeparator}rc_${fileBasenameNoExtension}.py"
],
}
pyside6自用用户片段
{
// Place your snippets for python here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"引用pyside6界面":{
"prefix": "inpyside6ui",
"body": [
"from Ui_untitled import Ui_MainWindow",
"from PySide6.QtGui import QGuiApplication",
"from PySide6 import QtWidgets",
"from PySide6.QtWidgets import QMainWindow, QMessageBox",
"class MainWindow(QMainWindow, Ui_MainWindow):",
"\tdef __init__(self, parent=None):",
"\t\tsuper(MainWindow, self).__init__(parent)",
"\t\tself.setupUi(self)",
"\t\t#执行窗口居中",
"\t\tself.center()",
"\t#-------------控制窗口显示到屏幕中心位置----------------------",
"\tdef center(self):",
"\t\tqr = self.frameGeometry()",
"\t\tcp = QGuiApplication.primaryScreen().availableVirtualGeometry().center()",
"\t\tqr.moveCenter(cp)",
"\t\tself.move(qr.topLeft())",
"\t#------------------------------------------------------------",
"if __name__ == '__main__':",
"\timport sys",
"\tapp = QtWidgets.QApplication(sys.argv)",
"\tui = MainWindow()",
"\tui.show()",
"\tsys.exit(app.exec_())"
],
},
"运行pyside6界面":{
"prefix": "runpyside6ui",
"body": [
"if __name__ == '__main__':",
"\timport sys",
"\tapp = QApplication(sys.argv)",
"\tMainWindow = QMainWindow()",
"\tui = Ui_MainWindow()",
"\tui.setupUi(MainWindow)",
"\tMainWindow.show()",
"\tsys.exit(app.exec_())"
],
}
}