首页 > 其他 > 详细

How can I add or import a picture to a QWidget?

时间:2014-04-23 12:47:56      阅读:472      评论:0      收藏:0      [点我收藏+]

A generic QWidget does not have setPixmap(). If this approach does not work for you, you can look at making your own custom widget that derives from QWidget and override the paintEvent method to display the image.


import os,sys
from PyQt4 import QtGui

app = QtGui.QApplication(sys.argv)
window = QtGui.QMainWindow()
window.setGeometry(0, 0, 400, 200)

pic = QtGui.QLabel(window)
pic.setGeometry(10, 10, 400, 100)
#use full ABSOLUTE path to the image, not relative
pic.setPixmap(QtGui.QPixmap(os.getcwd() + "/logo.png"))

window.show()
sys.exit(app.exec_())



How can I add or import a picture to a QWidget?,布布扣,bubuko.com

How can I add or import a picture to a QWidget?

原文:http://blog.csdn.net/gaoxin12345679/article/details/24348329

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!