1. pycharm创建工程 pyqt-res
2. 用Qt设计师创建一个包含qrc资源文件的ui文件
a. 启动designer
菜单栏: File->Tools->External tools 点击qtdesigner(或者 右键 工程目录 pyqt-res,External tools 点击qtdesigner)
便可启动 designer.
b. 资源管理器
c. 添加资源, 新建 资源文件
点击确定,工程目录,生产一个 qrc 资源文件,我这里是 res.qrc
3 . 转换资源文件
把qrc资源文件转换成十六进制的py文件
右键 工程目录 res.qrc, External tools 点击pyrcc.
目录下便生成一个 res.py
4 编写 mydlg.py
#!/usr/bin/env python
# encoding: utf-8
"""
@version : v4.5
@author : jiangxmin
@license :
@contact : jiang_xmin@massclouds.com
@site : http://blog.youkuaiyun.com/jxm_csdn
@software: PyCharm
@file : mydlg.py.py
@time : 16-7-3 下午4:17
"""
import sys
from PyQt4.QtGui import QApplication,QDialog, QPixmap, QPalette, QBrush
from PyQt4 import uic
import res # 导入资源文件 *****
class MyDlg(QDialog):
def __init__(self):
super(MyDlg, self).__init__()
uic.loadUi("mydlg.ui", self) # 加载ui文件 *****
self.setGeometry(50,50,800,600)
self.setAutoFillBackground(True)
# 设置窗口背景
pixmap = QPixmap(":/images/onepiece.jpg").scaled(self.size()) # 适应窗口大小
palette = QPalette()
palette.setBrush(QPalette.Window,QBrush(pixmap))
self.setPalette(palette)
if __name__ == '__main__':
app = QApplication(sys.argv)
dlg = MyDlg()
dlg.show()
app.exec_()
border="0" width="330" height="86" src="http://music.163.com/outchain/player?type=2&id=4965595&auto=1&height=66">