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. android fragment activity 区别

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha fragment  负责一个模块 的展示. 由 活动 管理. 碎片 可以 解决 太多活动 ...

  2. [BZOJ4873][六省联考2017]寿司餐厅(最大权闭合子图)

    4873: [Shoi2017]寿司餐厅 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 490  Solved: 350[Submit][Status ...

  3. 【期望DP】BZOJ2134- 单选错位

    [题目大意] 有n道题,第i道题有ai个选项.一个人把所有的正确答案填到了后面一题上(特殊的,当i=n的时候填到1上),问他期望做对几道题? [思路] 沙茶题……显然每道题的期望是独立的. 对于某道题 ...

  4. bzoj 1101

    其实这个用的是Mobius反演的第二种形式 F(d) = (n div d) * (m div d) f(d) = [ gcd(i,j)=d ] (i in [1,a], j in [1,b]) /* ...

  5. Miller_rabin算法+Pollard_rho算法 POJ 1811 Prime Test

    POJ 1811 Prime Test Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 32534   Accepted: 8 ...

  6. ngxin error日志

    日志模块ngx_errlog_module对于支持可变参数平台提供的三个接口 #define ngx_log_error(level, log, ...) \ if ((log)->log_le ...

  7. BZOJ 4443: [Scoi2015]小凸玩矩阵 最大流

    4443: [Scoi2015]小凸玩矩阵 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=4443 Description 小凸和小方是好 ...

  8. Codeforces Beta Round #5 B. Center Alignment 模拟题

    B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...

  9. 什么是 Backbone.js

    Backbone.js 是一个在JavaScript环境下的 模型-视图-控制器 (MVC) 框架.任何接触较大规模项目的开发人员一定会苦恼于各种琐碎的事件回调逻辑.以及金字塔般的代码.而且,在传统的 ...

  10. VS2010安装HTML5插件

    步骤: 1. 下载 插件 2.拷贝文件里面德尔html_5.xsd到 D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packa ...