Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1ba03d7

Browse filesBrowse files
committed
add minimal qt example
1 parent f4bab4a commit 1ba03d7
Copy full SHA for 1ba03d7

File tree

1 file changed

+35
-0
lines changed
Filter options

1 file changed

+35
-0
lines changed

‎examples/qt/minimal.py

Copy file name to clipboard
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Minimal PyQt example that displays an image. Press "r" key to autoscale
3+
"""
4+
from PyQt6 import QtWidgets
5+
import fastplotlib as fpl
6+
import imageio.v3 as iio
7+
8+
# Qt app MUST be instantiated before creating any fpl objects, or any other Qt objects
9+
app = QtWidgets.QApplication([])
10+
11+
img = iio.imread("imageio:astronaut.png")
12+
13+
# force qt canvas, wgpu will sometimes pick glfw by default even if Qt is present
14+
plot = fpl.Plot(canvas="qt")
15+
16+
plot.add_image(img)
17+
plot.camera.local.scale *= -1
18+
19+
# must call plot.show() to start rendering loop
20+
plot.show()
21+
22+
# set QWidget initial size from image width and height
23+
plot.canvas.resize(*img.shape[:2])
24+
25+
26+
def autoscale(ev):
27+
if ev.key == "r":
28+
plot.auto_scale()
29+
30+
31+
# useful if you pan/zoom away from the image
32+
plot.renderer.add_event_handler(autoscale, "key_down")
33+
34+
# execute Qt app
35+
app.exec()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.