Hello, I'm trying to do something I thought would be simple in PyQtGraph,
I'm trying to make a full screen image with zero scaling. I'm working on
Windows with a dual monitor display. I'd like to display the image (from
file at the moment) on the second monitor. I'm very close but maybe I'm
just going about things incorrectly. I can get the image to display full
screen on the second monitor, but there's some kind of scaling, the image
is too big. I'm surprised there is any scaling as I've set the ImageItem
to setPxMode(True) which states; If True, the item will not inherit any
scale or rotation transformations from its parent items, but its position
will be transformed as usual.
<http://www.pyqtgraph.org/documentation/graphicsItems/imageitem.html>
The code:
import numpy as np
from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
import pyqtgraph as pg
import cv2
class FsImageTool(QtGui.QMainWindow):
def __init__(self):
super(FsImageTool, self).__init__()
# two monitor setup, second monitor is 1920x1200
# show fullscreen application on second monitor
sg = QtGui.QDesktopWidget().screenGeometry(1)
print("screen geometry", sg)
self.move(sg.left(), sg.top())
self.showFullScreen()
# Create widget
self.glo = pg.GraphicsLayoutWidget()
self.setCentralWidget(self.glo)
self.imageViewBox = self.glo.addViewBox()
self.imageViewBox.setAspectLocked(True)
self.imageItem = pg.ImageItem()
# desire px mode because it basically says draws pixels directly,
no scaling
self.imageItem.setPxMode(True)
self.imageViewBox.addItem(self.imageItem)
# image of known size, should fit exactly on monitor
img = cv2.imread("1920x1200Image.tiff", -1)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
print("image shape", np.shape(img))
self.imageItem.setImage(img)
print("window bounds, before", self.glo.viewRect())
print("ViewBox bounds, before", self.imageViewBox.viewRect())
print("Image item bounds, before", self.imageItem.viewRect())
self.imageViewBox.setRange(sg, padding=0)
rect = self.imageItem.viewRect()
# not even sure why i really need to do this
rect.translate(0, -1200)
self.imageItem.setRect(rect)
print("self bounds, after", self.glo.viewRect())
print("ViewBox bounds, after", self.imageViewBox.viewRect())
print("Image item bounds, after", self.imageItem.viewRect())
print("Screen geometry of image", self.imageViewBox.screenGeometry
())
if __name__ == '__main__':
import sys
app = QtGui.QApplication([])
imageViewer = FsImageTool()
imageViewer.show()
sys.exit(app.exec_())
The output:
screen geometry PyQt5.QtCore.QRect(-1920, -432, 1920, 1200)
image shape (1920, 1200, 3)
window bounds, before PyQt5.QtCore.QRectF(0.0, 0.0, 640.0, 480.0)
ViewBox bounds, before PyQt5.QtCore.QRectF(-0.5, -0.5, 1.0, 1.0)
Image item bounds, before PyQt5.QtCore.QRectF(-0.5, -0.5, 1.0, 1.0)
self bounds, after PyQt5.QtCore.QRectF(0.0, 0.0, 640.0, 480.0)
ViewBox bounds, after PyQt5.QtCore.QRectF(-38.4, -24.0, 1996.8000000000002,
1248.0)
Image item bounds, after PyQt5.QtCore.QRectF(7.105427357601002e-15,
1153.8461538461538, 1920.0, 1200.0)
Screen geometry of image PyQt5.QtCore.QRect(-1920, -432, 1, 1)
What I see on the screen:
The left side of the image is correct. The top, right and bottom border
are all about 10-20 pixels off screen
The goal:
1 to 1 pixel mapping of monitor to image where I can update the image
(programatically) and display it quickly.
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/981d5a69-fa98-4ea5-92d6-7797fcba29d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.