-
大小: 6KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-05-25
- 语言: Python
- 标签: PyQt python QGraphicsVie
资源简介
利用pyQt读取并显示图像的案例,非常好的学习资源,我就是通过它开始了python程序员之路,这个小程序实现了人生买房的梦想。
代码片段和文件信息
“““ QtImageViewer.py: PyQt image viewer widget for a QPixmap in a QGraphicsView scene with mouse zooming and panning.
“““
import os.path
try:
from PyQt5.QtCore import Qt QRectF pyqtSignal QT_VERSION_STR
from PyQt5.QtGui import QImage QPixmap QPainterPath
from PyQt5.QtWidgets import QGraphicsView QGraphicsScene QFileDialog
except ImportError:
try:
from PyQt4.QtCore import Qt QRectF pyqtSignal QT_VERSION_STR
from PyQt4.QtGui import QGraphicsView QGraphicsScene QImage QPixmap QPainterPath QFileDialog
except ImportError:
raise ImportError(“ImageViewerQt: Requires PyQt5 or PyQt4.“)
__author__ = “Marcel Goldschen-Ohm “
__version__ = ‘0.9.0‘
class QtImageViewer(QGraphicsView):
“““ PyQt image viewer widget for a QPixmap in a QGraphicsView scene with mouse zooming and panning.
Displays a QImage or QPixmap (QImage is internally converted to a QPixmap).
To display any other image format you must first convert it to a QImage or QPixmap.
Some useful image format conversion utilities:
qimage2ndarray: NumPy ndarray <==> QImage (https://github.com/hmeine/qimage2ndarray)
ImageQt: PIL Image <==> QImage (https://github.com/python-pillow/Pillow/blob/master/PIL/ImageQt.py)
Mouse interaction:
Left mouse button drag: Pan image.
Right mouse button drag: Zoom box.
Right mouse button doubleclick: Zoom to show entire image.
“““
# Mouse button signals emit image scene (x y) coordinates.
# !!! For image (row column) matrix indexing row = y and column = x.
leftMouseButtonPressed = pyqtSignal(float float)
rightMouseButtonPressed = pyqtSignal(float float)
leftMouseButtonReleased = pyqtSignal(float float)
rightMouseButtonReleased = pyqtSignal(float float)
leftMouseButtonDoubleClicked = pyqtSignal(float float)
rightMouseButtonDoubleClicked = pyqtSignal(float float)
def __init__(self):
QGraphicsView.__init__(self)
# Image is displayed as a QPixmap in a QGraphicsScene attached to this QGraphicsView.
self.scene = QGraphicsScene()
self.setScene(self.scene)
# Store a local handle to the scene‘s current image pixmap.
self._pixmapHandle = None
# Image aspect ratio mode.
# !!! ONLY applies to full image. Aspect ratio is always ignored when zooming.
# Qt.IgnoreAspectRatio: Scale image to fit viewport.
# Qt.KeepAspectRatio: Scale image to fit inside viewport preserving aspect ratio.
# Qt.KeepAspectRatioByExpanding: Scale image to fill the viewport preserving aspect ratio.
self.aspectRatioMode = Qt.KeepAspectRatio
# Scroll bar behaviour.
# Qt.ScrollBarAlwaysOff: Never shows a scroll bar.
# Qt.ScrollBarAlwaysOn: Always shows a scroll bar.
# Qt.ScrollBarAsNeeded: Shows a scroll bar only when zoomed.
self.setHorizontalScrollBarPolicy(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-12-02 17:26 PyQtImageViewer-master\
文件 471 2017-12-02 17:26 PyQtImageViewer-master\.gitignore
文件 1088 2017-12-02 17:26 PyQtImageViewer-master\LICENSE
文件 9541 2017-12-02 17:26 PyQtImageViewer-master\QtImageViewer.py
文件 3700 2017-12-02 17:26 PyQtImageViewer-master\README.md
相关资源
- python实现的ping工具
- 基于PYQT编写的人脸识别软件
- 续Python3.x+PyQtChart实现数据可视化界面
- PyQt5中异步刷新UI+Python中的多线程+p
- 计算机图形学课程代码资源.zip
- 中点画圆算法pyqt5实现.zip
- 数字图像处理Python制作简易软件系统
- PYQT5+图片拖拽
- PyQt4中文教程chm版
- 使用pyqt5实现的Python-GUI动态作图
- 鱼c小甲鱼零基础学python全套视频和课
- Python3.x+Pyqt5实现主窗体与子窗体相互
- 零基础学习python pygame 飞机大战可执行
- PyQt5实时显示Camera
- 零基础学习python视频100集全百度云.
- python 打印信息重定向 GUI界面 ,PyQt
- pyqt5下连接sqlite3并显示
- python+pyqt5 做上位机界面
- PyQt5CheckBox简单界面
- PYQT5写字板
-
pyqt5+requests+bs4+lxm
l+urllib阅读小说窗 - PyQt5 入门级
- PyQt5对txt简单增删查改管理学生信息
- 《Python Qt GUI快速编程 PyQt编程指南》
- pyqt5天气查询系统
- pyqt5俄罗斯方块 源码
- pyqt5图书管理系统源码+安装说明+数据
- PyQt5标准对话框 获取用户输入
- 简单窗口(Python+pyQT)入门级
- 零基础学python
评论
共有 条评论