File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments