Scrolling
ImageViewer
Lets people zoom around the pointer and pan a single image, with fit and actual-size views.
Example

Usage
Pan and zoom an image
The wheel, a pinch or Ctrl/Command + wheel zooms around the pointer, dragging pans, and the toolbar appears on hover.
#include <FluentQt/Scrolling.h>
using namespace fluent::scrolling;
auto* viewer = new ImageViewer(this);
viewer->setMaximumWidth(460);
viewer->setFixedHeight(290);
viewer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
viewer->setAccessibleName(QStringLiteral("Harbor at dusk"));
viewer->setPixmap(imageViewerScene(QSize(1600, 1000), 0));
// Double-click toggles 100%; after focus, + - 0 1 and the
// arrow keys zoom, reset and pan.
auto updateStatus = [viewer, status] {
status->setText(imageViewerStatusText(viewer));
};
connect(viewer, &ImageViewer::zoomFactorChanged, status, updateStatus);
connect(viewer, &ImageViewer::fitModeChanged, status, updateStatus);import fluentqt
from PySide6.QtCore import QSize
from PySide6.QtWidgets import QSizePolicy
viewer = fluentqt.ImageViewer()
viewer.setMaximumWidth(460)
viewer.setFixedHeight(290)
viewer.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
viewer.setAccessibleName('Harbor at dusk')
viewer.setPixmap(image_viewer_scene(QSize(1600, 1000), 0))
def update_status(*_args):
status.setText(image_viewer_status_text(viewer))
viewer.zoomFactorChanged.connect(update_status)
viewer.fitModeChanged.connect(update_status)API
DeclarationNo matching API members.
fluent::scrolling::ImageViewer
Inherits QWidget · FluentElement · QMLPlus
Pan-and-zoom viewer for a single image.
Constructors
Properties
QPixmap pixmapImage shown by the viewer; setting a new one resets the view.
Readpixmap()WritesetPixmap()NotifypixmapChanged()qreal zoomFactorCurrent zoom factor; 1.0 is the image's device-independent size.
ReadzoomFactor()WritesetZoomFactor()NotifyzoomFactorChanged()qreal minZoomFactorSmallest zoom factor; the fit factor stays reachable below it.
ReadminZoomFactor()WritesetMinZoomFactor()NotifyminZoomFactorChanged()qreal maxZoomFactorLargest zoom factor; the fit factor stays reachable above it.
ReadmaxZoomFactor()WritesetMaxZoomFactor()NotifymaxZoomFactorChanged()QPointF viewCenterImage point, in device-independent image pixels, shown at the viewport center.
ReadviewCenter()WritesetViewCenter()NotifyviewCenterChanged()FitMode fitModeWhether the view follows a fit rule when the viewport resizes.
ReadfitMode()WritesetFitMode()NotifyfitModeChanged()WheelAction wheelActionWhat an unmodified mouse wheel does.
ReadwheelAction()WritesetWheelAction()NotifywheelActionChanged()ControlsVisibility controlsVisibilityVisibility policy of the built-in zoom controls.
ReadcontrolsVisibility()WritesetControlsVisibility()NotifycontrolsVisibilityChanged()bool zoomIndicatorEnabledWhether direct zoom input briefly shows the zoom percentage when the controls are hidden.
ReadisZoomIndicatorEnabled()WritesetZoomIndicatorEnabled()NotifyzoomIndicatorEnabledChanged()bool frameVisibleWhether the viewer paints its rounded background and border.
ReadisFrameVisible()WritesetFrameVisible()NotifyframeVisibleChanged()Qt::TransformationMode transformationModeSampling used to scale the image; Fast keeps individual pixels sharp.
ReadtransformationMode()WritesetTransformationMode()NotifytransformationModeChanged()
Methods
QPixmap pixmap() constImage shown by the viewer; setting a new one resets the view.
void setPixmap(const QPixmap& pixmap)Image shown by the viewer; setting a new one resets the view.
void setImage(const QImage& image)Converts an image to a pixmap and shows it.
QSizeF imageSize() constReturns the image's device-independent size, or an empty size without an image.
qreal fitZoomFactor() constReturns the factor that fits the whole image into the current viewport.
qreal zoomFactor() constCurrent zoom factor; 1.0 is the image's device-independent size.
void setZoomFactor(qreal factor)Current zoom factor; 1.0 is the image's device-independent size.
qreal minZoomFactor() constSmallest zoom factor; the fit factor stays reachable below it.
void setMinZoomFactor(qreal factor)Smallest zoom factor; the fit factor stays reachable below it.
qreal maxZoomFactor() constLargest zoom factor; the fit factor stays reachable above it.
void setMaxZoomFactor(qreal factor)Largest zoom factor; the fit factor stays reachable above it.
QPointF viewCenter() constImage point, in device-independent image pixels, shown at the viewport center.
void setViewCenter(const QPointF& center)Image point, in device-independent image pixels, shown at the viewport center.
FitMode fitMode() constWhether the view follows a fit rule when the viewport resizes.
void setFitMode(FitMode mode)Whether the view follows a fit rule when the viewport resizes.
WheelAction wheelAction() constWhat an unmodified mouse wheel does.
void setWheelAction(WheelAction action)What an unmodified mouse wheel does.
ControlsVisibility controlsVisibility() constVisibility policy of the built-in zoom controls.
void setControlsVisibility(ControlsVisibility visibility)Visibility policy of the built-in zoom controls.
bool isZoomIndicatorEnabled() constWhether direct zoom input briefly shows the zoom percentage when the controls are hidden.
void setZoomIndicatorEnabled(bool enabled)Whether direct zoom input briefly shows the zoom percentage when the controls are hidden.
bool isFrameVisible() constWhether the viewer paints its rounded background and border.
void setFrameVisible(bool visible)Whether the viewer paints its rounded background and border.
Qt::TransformationMode transformationMode() constSampling used to scale the image; Fast keeps individual pixels sharp.
void setTransformationMode(Qt::TransformationMode mode)Sampling used to scale the image; Fast keeps individual pixels sharp.
void zoomIn(bool animated = false)Zooms in to the next preset step around the viewport center.
void zoomOut(bool animated = false)Zooms out to the previous preset step around the viewport center.
void zoomTo(qreal factor, bool animated = false)Zooms to a factor around the viewport center.
void zoomTo(qreal factor, const QPointF& viewportAnchor, bool animated = false)Zooms to a factor while keeping the image point under a viewport position fixed.
void zoomToActualSize(bool animated = false)Shows the image at 100% around the viewport center.
void fitToView(bool animated = false)Fits the whole image into the viewport and keeps fitting on resize.
void resetView(bool animated = false)Returns to the initial view: large images fit, small images stay at 100%.
void panBy(qreal dx, qreal dy)Moves the visible region by viewport pixels; positive values reveal the right and bottom.
QPointF mapToImage(const QPointF& viewportPoint) constMaps a viewport position to device-independent image coordinates.
QPointF mapFromImage(const QPointF& imagePoint) constMaps device-independent image coordinates to a viewport position.
Signals
void pixmapChanged()Image shown by the viewer; setting a new one resets the view.
void zoomFactorChanged(qreal factor)Current zoom factor; 1.0 is the image's device-independent size.
void minZoomFactorChanged(qreal factor)Smallest zoom factor; the fit factor stays reachable below it.
void maxZoomFactorChanged(qreal factor)Largest zoom factor; the fit factor stays reachable above it.
void viewCenterChanged(const QPointF& center)Image point, in device-independent image pixels, shown at the viewport center.
void fitModeChanged(fluent::scrolling::ImageViewer::FitMode mode)Whether the view follows a fit rule when the viewport resizes.
void wheelActionChanged(fluent::scrolling::ImageViewer::WheelAction action)What an unmodified mouse wheel does.
void controlsVisibilityChanged(fluent::scrolling::ImageViewer::ControlsVisibility visibility)Visibility policy of the built-in zoom controls.
void zoomIndicatorEnabledChanged(bool enabled)Whether direct zoom input briefly shows the zoom percentage when the controls are hidden.
void frameVisibleChanged(bool visible)Whether the viewer paints its rounded background and border.
void transformationModeChanged(Qt::TransformationMode mode)Sampling used to scale the image; Fast keeps individual pixels sharp.
Enumerations
enum class FitModeFit rule followed by the view.
ManualKeeps the zoom factor and view center.ContainFits the whole image, enlarging small images.ScaleDownFits large images and keeps small ones at 100%.
enum class WheelActionAction of an unmodified mouse wheel.
ZoomZooms around the pointer.PanPans, or passes the wheel to the parent without range.
enum class ControlsVisibilityVisibility policy of the zoom controls.
HiddenNever shown.AutoShown while hovered, focused or dragged.VisibleAlways shown while an image is set.
Destructors
Subclass interfaces
Methods
Inherited from fluent::FluentElement
Methods
static void setTheme(Theme theme)Updates the global theme and notifies active FluentElement instances.
static void setThemeDeferred(Theme theme)Schedules a visible-first batched theme refresh without blocking the current interaction.
static Theme currentTheme()Returns the currently active global theme.
static bool themeUsesDarkAppearance(Theme theme)Returns whether a theme uses dark-backed chrome and material tokens.
static void refreshTheme()Re-broadcasts the current theme to repaint after a design-token change.
static int themeGeneration()Monotonic counter bumped on every theme change, for staleness checks.
Theme effectiveTheme() constResolves the theme used by this element, honoring an inherited QWidget override.
bool effectiveThemeUsesDarkAppearance() constReturns whether this element's effective theme uses dark-backed chrome.
bool setThemeOverrides(const QJsonObject& overrides)Component-facing token accessors.
QJsonObject themeOverrides() constReturns this element's authored overrides.
void clearThemeOverrides()Restores all token fields to global theme defaults.
const Colors& themeColorsRef() constNon-copying access to the active color set (for hot paint paths).
Material::AcrylicToken themeAcrylic() constMaterial, elevation, and adaptive layout tokens.
QColor themeBackdrop(bool active) constWindow-chrome backdrop color for the given activation state.
virtual void onThemeUpdated()Called after the global theme changes.
Enumerations
enum ThemeGlobal visual theme used when resolving design tokens.
Light = 0Dark = 1HighContrast = 2
Types and aliases
struct ColorsDesign token snapshots returned to components.
Inherited from fluent::QMLPlus
Methods
AnchorLayout::Anchors* anchors()Returns mutable anchors for the QWidget host.
void setState(const QString& name)Applies a named state, or clears state when name is empty.
void addState(const QMLState& state)Registers or replaces a named state definition.
void evaluateStates()Reevaluates conditions; the first registered true condition wins.
QMLPlusRuntime* runtime()Returns the lazy host-owned state observation object.
void setAnchors(const AnchorLayout::Anchors& anchors)Replaces all host anchors and invalidates the parent layout.
void resetAnchors()Clears all host anchors and invalidates the parent layout.
void bind(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction dir = PropertyBinder::OneWay)Binds a source property to a property on the QWidget host.
BindingHandle bindManaged(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction direction = PropertyBinder::OneWay, BindingOptions options = {})Installs a managed direct binding on this QWidget host.
BindingHandle bindComputed(const char* targetProp, const QVector<BindingDependency>& dependencies, std::function<QVariant()> evaluate, BindingOptions options = {})Installs an explicit-dependency C++ expression on this QWidget host.
void addTransition(const StateTransition& transition)Registers a state transition in precedence order.
void setBehavior(const char* propertyName, const PropertyAnimation& animation)Sets the default animation for this host's managed property writes.
void clearBehavior(const char* propertyName)Removes the default animation for future managed writes.
bool writeProperty(const char* propertyName, const QVariant& value)Writes a host property through Behavior without removing its binding.
All inherited Qt members:QWidget