系统相关
首页 > 系统相关> > Ubuntu下在PyQt设计的界面上显示图片

Ubuntu下在PyQt设计的界面上显示图片

作者:互联网

继续上一篇博客Ubuntu下Pycharm配置pyqt5来做界面_jiugeshao的专栏-CSDN博客,在界面上加入图像的显示功能。

通过命令来安装python下的opencv库

pip install opencv-python

 安装完毕后,继续在前面博客设计的界面上加入QLabel控件

设计完毕后,重新生成对应的form.py文件

修改前面博客testgui2.py中的代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author:Icecream.Shao
from form import Ui_Form
from PyQt5 import QtWidgets
import sys
import cv2
from PyQt5.Qt import QImage
from PyQt5.Qt import QPixmap

class Mywindow(QtWidgets.QMainWindow, Ui_Form):
    def __init__(self):
        super(Mywindow, self).__init__()
        self.setupUi(self)

    def slot1(self):
        self.textEdit.setText(("hi,helloworld~"))
        image = cv2.imread("/home/icecreamshao/108.bmp")
        dstimage = cv2.cvtColor(image, cv2.COLOR_BGR2RGB);
        Qtemp = QImage(dstimage[:], dstimage.shape[1], dstimage.shape[0], dstimage.shape[1] * 3, QImage.Format_RGB888)
        pixmap_Qtemp = QPixmap.fromImage(Qtemp)
        # pixmap_Qtemp = QPixmap.fromImage(Qtemp).scaled(self.label.width(), self.label.height())
        self.label.setPixmap(pixmap_Qtemp)
        self.label.resize(Qtemp.size())

app = QtWidgets.QApplication(sys.argv)
window = Mywindow()
window.show()
sys.exit(app.exec_())

 运行程序,结果如下:

 

标签:Qtemp,界面,dstimage,self,cv2,PyQt,label,Ubuntu,import
来源: https://blog.csdn.net/jiugeshao/article/details/120603859