-
大小: 6KB文件類型: .zip金幣: 2下載: 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
評論
共有 條評論