QtGui.QPixmap is one of the widgets used to work with images. It is optimized for showing images on screen. In our code example, we will use the QtGui.QPixmap to display an image on the window.

#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In this example, we dispay an image
on the window. author: Jan Bodnar
website: zetcode.com
last edited: September 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): hbox = QtGui.QHBoxLayout(self)
pixmap = QtGui.QPixmap("redrock.png") lbl = QtGui.QLabel(self)
lbl.setPixmap(pixmap) hbox.addWidget(lbl)
self.setLayout(hbox) self.move(300, 200)
self.setWindowTitle('Red Rock')
self.show() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()

In our example, we display an image on the window.

pixmap = QtGui.QPixmap("redrock.png")

We create a QtGui.QPixmap object. It takes the name of the file as a parameter.

lbl = QtGui.QLabel(self)
lbl.setPixmap(pixmap)

We put the pixmap into the QtGui.QLabel widget.

QtGui.QPixmap的更多相关文章

  1. QtGui.QSlider

    A QtGui.QSlider is a widget that has a simple handle. This handle can be pulled back and forth. This ...

  2. 怎样把ndarray转换为PyQt中的QPixmap

    找不到文档,只在网上找到一些语焉不详,执行错误的代码,鼓捣了一个晚上,研(luan)究(gao)成功 def img2pixmap(self, image): Y, X = image.shape[: ...

  3. Pyqt 基础功能

    总结Pyqt的基础知识 1. Pyqt  设置禁止最大化及禁止拖拽窗口大小 # PyQT禁止窗口最大化按钮: self.setWindowFlags(QtCore.Qt.WindowMinimizeB ...

  4. Python 创建本地服务器环境生成二维码

    一. 需求 公司要做一个H5手机端适配页面,因技术问题所以H5是外包的,每次前端给我们源码,我们把源码传到服务器让其他人访问看是否存在bug,这个不是很麻烦吗?有人说,可以让前端在他们的服务器上先托管 ...

  5. Pyqt+QRcode 生成 识别 二维码

    1.生成二维码 python生成二维码是件很简单的事,使用第三方库Python QRCode就可生成二维码,我用Pyqt给QRcode打个壳 一.python-qrcode介绍 python-qrco ...

  6. pyside 为窗口添加图片

    有时我们需要添加一些图片到窗口上,下面给一个通过QLable实现的方法. 这里需要注意的是,当你启用多线程时,方法调用的setPixmap,会导致qt报出一个线程安全错误. 因此,让这个绘图工作尽量在 ...

  7. getWinSystemIcon

    #include <QtGui/QImage>#include <QtGui/QPixmap>void getSystemIcon(const chConstStringA&a ...

  8. 从RAM新建QIcon对象 / Create a QIcon from binary data

    一般,QIcon是通过png或ico等图标文件来初始化的,但是如果图标资源已经在内存里了,或者一个zip压缩文件内,可以通过QPixmap作为桥梁,转换为图标. zf = zipfile.ZipFil ...

  9. Pyqt 获取windows系统中已安装软件列表

    开始之前的基础知识 1. 获取软件列表 在Python的标准库中,_winreg可以操作Windows的注册表.获取已经安装的软件列表一般是读去windows的注册表: SOFTWARE\Micros ...

随机推荐

  1. 数位dp小结以及模板

    这里是网址 别人的高一啊QAQ.... 嗯一般记忆化搜索是比递推好写的所以我写的都是dfs嗯......(因为我找不到规律啊摔,还是太菜.....) 显然这个东西的条件是非常的有套路..但是不管怎么样 ...

  2. bzoj 3165

    题意: 给出平面上一些线段,在线询问与x=x0相交的线段中,交点y最大的线段的标号,支持添加线段. 大概思路: 用线段树维护,线段树每个线段记录贯穿(左右端点在该区间外或上)的原线段中能覆盖其它贯穿该 ...

  3. OpenAPI安全防护

    1,开放API可能存在的数据安全问题 (1)数据窃取 通常体现为:钓鱼网站,拦截,伪装,截包 (2)数据篡改 中间被拦截,以代理的方式拦截数据,修改数据 (3)数据泄露 爬虫抓取核心数据 2,解决数据 ...

  4. mysqldump导出CSV格式及where导出时间范围问题解决

    众所周知,mysqldump不但可以导出sql格式,还可以导出csv格式. 导出CSV格式的具体使用如下命令. mysqldump -uroot -ppassword -S /tmp/mysql999 ...

  5. 一些WPF中的滤镜特效——Effect Library

    WPF支持类似PhotoShop的滤镜功能,称之为Effect.在.Net 4.0中,WPF就废弃了对BitMapEffect的支持,转向使用支持GPU加速的Effect类,例如,我们可以使用如下代码 ...

  6. Java-方法的覆写

    class  parent {  void print()  {  System.out.println("parent");  } } class child extends p ...

  7. Linux Kernel 4.9 & BBR

    https://www.mxgw.info/t/linux-kernel-4-9-bbr.html?utm_source=tuicool&utm_medium=referral

  8. find命令专辑

    find命令使用技巧 查找文件,移动到某个目录 使用find和xargs 15条 linux Find 命令实际使用方法 find 命令用法 find命令使用经验 find用法小结 find与xarg ...

  9. iTunes Connect App Bundles

    App Bundles捆绑销售提交流程: 1. 在iTunes Connect左上「+」选「Create Bundle」到「New App Bundle」挑选已上线应用(最多可捆绑10个应用) 2. ...

  10. 【mysql】二级索引----聚簇索引和非聚簇索引-----

    参考地址: https://blog.csdn.net/bigtree_3721/article/details/51335479 https://blog.csdn.net/roxliu/artic ...