2016/7/20 21:22:32 PyQT5 设置窗口icon / 显示图片

2016/7/20 21:22:32  使用QIcon
  1. from PyQt5.Qt import QIcon
  2. self.setWindowIcon(QIcon('img/0719/Icon.jpg'))
效果:
 
2016/7/20 21:38:21 加载本地图片
 code:
  1. from PyQt5.QtCore import *
  2. from PyQt5.QtGui import *
  3. from PyQt5.QtWidgets import *
  4. from PyQt5.Qt import QDir, QIcon
  5. import sys
  6. class Window(QWidget):
  7. def __init__(self):
  8. super(Window, self).__init__()
  9. self.setWindowTitle('Qt_Group')
  10. self.resize(500,500)
  11. self.setWindowIcon(QIcon('img/0719/TB1AeYWKVXXXXcmXVXXSutbFXXX.jpg_460x460xz.jpg'))
  12. self.echoGroup = QGroupBox('Echo')
  13. self.echoLabel = QLabel(self)
  14. self.echoLabel.setFixedSize(460,460)
  15. self.movieImage = QImage('img/0719/TB1AeYWKVXXXXcmXVXXSutbFXXX.jpg_460x460xz.jpg')
  16. self.echoLabel.setPixmap(QPixmap.fromImage(self.movieImage).scaled(self.echoLabel.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation))
  17. self.echoLayout = QGridLayout()
  18. self.echoLayout.addWidget(self.echoLabel, 0, 0)
  19. self.echoGroup.setLayout(self.echoLayout)
  20. self.Layout = QGridLayout()
  21. self.Layout.addWidget(self.echoGroup, 0, 0)
  22. self.setLayout(self.Layout)
  23. app = QApplication(sys.argv)
  24. win = Window()
  25. win.show()
  26. app.exec_()





posted @ 2016-09-06 10:44  乾坤颠倒  阅读(1674)  评论(0编辑  收藏  举报