简体   繁体   English

将图像 url 插入单元格表格小部件 python

[英]Insert image url into cell tablewidget python

I have problem with insert image from url to cell in tablewidget pyqt5 in python.我在将图像从 url 插入到 python 中的表格小部件 pyqt5 中的单元格时遇到问题。 I want show image in cell.我想在单元格中显示图像。 You can see my table on the image from attachments.您可以在附件中的图片上看到我的桌子。 When i use my code (below) i do not get anything (zero images) in my cell.Please show me way to do this.当我使用我的代码(如下)时,我的单元格中没有任何内容(零图像)。请告诉我如何做到这一点。

# sample link with image i use from loop: 
#https://a.allegroimg.com/original/037495/be1ecbef43e7a2039a0bc42ceddf.jpg
zdi2 = 'https://a.allegroimg.com/original/037495/be1ecbef43e7a2039a0bc42ceddf.jpg'
data = urllib.urlopen(zdi2).read()
pixmap = QPixmap()
pixmap.loadFromData(data)
icon = QIcon(pixmap)
self.tableWidget_14.setItem(row_numer13,1,QTableWidgetItem(icon))

my tablewidget picture我的桌面小部件图片

Problem solved.问题解决了。 Solution is QLabel:解决方案是 QLabel:

zdi2 = 'https://a.allegroimg.com/original/037495/be1ecbef43e7a2039a0bc42ceddf.jpg'
r = requests.get(zdi2,stream=True)
assert r.status_code == 200
img = QImage()
assert img.loadFromData(r.content)
w = QLabel()
w.setPixmap(QPixmap.fromImage(img))
w.setGeometry(0,0,5,5)
w.resize(20,20)
self.tableWidget_14.setCellWidget(row_numer13,1,w)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM