Skip to content

update qt examples #485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions examples/qt/video.py → examples/qt/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,22 @@
import fastplotlib as fpl
import imageio.v3 as iio

# Qt app MUST be instantiated before creating any fpl objects, or any other Qt objects
app = QtWidgets.QApplication([])

video = iio.imread("imageio:cockatoo.mp4")

# force qt canvas, wgpu will sometimes pick glfw by default even if Qt is present
plot = fpl.Plot(canvas="qt")
# fastplotlib and wgpu will auto-detect if Qt is imported and then use the Qt canvas and output context
fig = fpl.Figure()

plot.add_image(video[0], name="video")
plot.camera.local.scale *= -1
fig[0, 0].add_image(video[0], name="video")


def update_frame(ix):
plot["video"].data = video[ix]
# you can also do plot.graphics[0].data = video[ix]
fig[0, 0]["video"].data = video[ix]
# you can also do fig[0, 0].graphics[0].data = video[ix]


# create a QMainWindow, set the plot canvas as the main widget
# The canvas does not have to be in a QMainWindow and it does
# not have to be the central widget, it will work like any QWidget
# create a QMainWindow
main_window = QtWidgets.QMainWindow()
main_window.setCentralWidget(plot.canvas)

# Create a QSlider for updating frames
slider = QtWidgets.QSlider(QtCore.Qt.Orientation.Horizontal)
Expand All @@ -44,8 +38,11 @@ def update_frame(ix):
dock
)

# calling plot.show() is required to start the rendering loop
plot.show()
# calling fig.show() is required to start the rendering loop
qwidget = fig.show()

# set the qwidget as the central widget
main_window.setCentralWidget(qwidget)

# set window size from width and height of video
main_window.resize(video.shape[2], video.shape[1])
Expand All @@ -54,4 +51,4 @@ def update_frame(ix):
main_window.show()

# execute Qt app
app.exec()
fpl.run()
15 changes: 9 additions & 6 deletions examples/qt/imagewidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import numpy as np
from PyQt6 import QtWidgets
import fastplotlib as fpl
import imageio.v3 as iio

# Qt app MUST be instantiated before creating any fpl objects, or any other Qt objects
app = QtWidgets.QApplication([])

images = np.random.rand(100, 512, 512)

# create image widget, force Qt canvas so it doesn't pick glfw
iw = fpl.ImageWidget(images, grid_plot_kwargs={"canvas": "qt"})
# fastplotlib and wgpu will auto-detect if Qt is imported and then use the Qt canvas
iw = fpl.ImageWidget(images)
iw.show()
iw.widget.resize(800, 800)

Expand All @@ -20,10 +19,14 @@

iw_mult = fpl.ImageWidget(
images_list,
grid_plot_kwargs={"canvas": "qt"},
cmap="viridis"
)
iw_mult.show()
iw_mult.widget.resize(800, 800)

app.exec()
# image widget with rgb data
rgb_video = iio.imread("imageio:cockatoo.mp4")
iw_rgb = fpl.ImageWidget(rgb_video, rgb=[True])
iw_rgb.show()

fpl.run()
29 changes: 9 additions & 20 deletions examples/qt/minimal.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
"""
Minimal PyQt example that displays an image. Press "r" key to autoscale
"""
# import Qt or PySide
from PyQt6 import QtWidgets
import fastplotlib as fpl
import imageio.v3 as iio

# Qt app MUST be instantiated before creating any fpl objects, or any other Qt objects
app = QtWidgets.QApplication([])

img = iio.imread("imageio:astronaut.png")

# force qt canvas, wgpu will sometimes pick glfw by default even if Qt is present
plot = fpl.Plot(canvas="qt")
# fastplotlib and wgpu will auto-detect if Qt is imported and then use the Qt canvas and Qt output context
fig = fpl.Figure()

plot.add_image(img)
plot.camera.local.scale *= -1
fig[0, 0].add_image(img)

# must call plot.show() to start rendering loop
plot.show()
# must call fig.show() to start rendering loop and show the QWidget containing the fastplotlib figure
qwidget = fig.show()

# set QWidget initial size from image width and height
plot.canvas.resize(*img.shape[:2])


def autoscale(ev):
if ev.key == "r":
plot.auto_scale()


# useful if you pan/zoom away from the image
plot.renderer.add_event_handler(autoscale, "key_down")
qwidget.resize(*img.shape[:2])

# execute Qt app
app.exec()
# if this is part of a larger Qt QApplication, you can also call app.exec() where app is the QApplication instance
fpl.run()
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy