Wireshark 5.1.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
ZoomScaling Namespace Reference

Text zoom scaling of pixel lengths and widget metrics. More...

Functions

int scaledPixels (int px, qreal factor)
 Scales a pixel value designed for zoom level 0 by factor.
int scaledSizeLimit (int design, qreal factor)
 Scales one component of a widget size limit by factor.
QString scaleStyleSheetLengths (const QString &qss, qreal factor)
 Scales the pixel lengths of a stylesheet by factor.
Current zoom level
int scaledPixels (int px)
int scaledSizeLimit (int design)
void scaleSizeLimits (QWidget *widget)
void scaleIconSize (QWidget *widget)
void scaleLayoutMetrics (QLayout *layout)
int barIconSize ()

Detailed Description

Text zoom scaling of pixel lengths and widget metrics.

The functions that take a factor depend on nothing but Qt and are covered by qt_zoom_scaling_test; the others use the current zoom level of FontManager and follow its zoom changes.

Function Documentation

◆ barIconSize()

int ZoomScaling::barIconSize ( )

Side in pixels of the display filter toolbar and status bar icons at the current zoom level (14 at zoom 0). Not derived from the status bar font, which is smaller on macOS, nor from a style metric.

◆ scaledPixels() [1/2]

int ZoomScaling::scaledPixels ( int px)

Scales a pixel value that is designed for zoom level 0 by the current zoom factor, FontManager::zoomFactor(). 0 stays 0; any other value is at least 1.

Parameters
pxnon-negative pixel value at zoom level 0.
Returns
the value at the current zoom level.

◆ scaledPixels() [2/2]

int ZoomScaling::scaledPixels ( int px,
qreal factor )

Scales a pixel value designed for zoom level 0 by factor.

0 stays 0; any other value is at least 1.

◆ scaledSizeLimit() [1/2]

int ZoomScaling::scaledSizeLimit ( int design)

Scales one component of a widget size limit (minimum or maximum width or height) designed for zoom level 0. 0, 1 and QWIDGETSIZE_MAX (unlimited) are returned unchanged at every zoom level, so resets, hairlines and "no limit" stay; any other value goes through scaledPixels().

Parameters
designthe limit at zoom level 0.
Returns
the limit at the current zoom level.

◆ scaledSizeLimit() [2/2]

int ZoomScaling::scaledSizeLimit ( int design,
qreal factor )

Scales one component of a widget size limit by factor.

0, 1 and QWIDGETSIZE_MAX (unlimited) are returned unchanged, so resets, hairlines and "no limit" stay; any other value goes through scaledPixels(design, factor).

◆ scaleIconSize()

void ZoomScaling::scaleIconSize ( QWidget * widget)

Makes the icon size of widget follow the zoom level.

The first call stores the widget's current iconSize as its zoom level 0 design value (call it after setupUi() or after the one setIconSize() call), and updates the icon size on every zoom change for the widget's lifetime. Later calls only re-apply the stored value. Each component goes through scaledPixels(). Works on any widget with an iconSize property (QAbstractButton, QToolBar, QAbstractItemView); other widgets are ignored.

Parameters
widgetthe widget to scale; nullptr is ignored.

◆ scaleLayoutMetrics()

void ZoomScaling::scaleLayoutMetrics ( QLayout * layout)

Makes the contents margins and spacing of layout follow the zoom level.

The first call stores the layout's current contentsMargins() and spacing() as their zoom level 0 design values (call it after setupUi() or after the layout's own margin and spacing calls), and updates them on every zoom change for the layout's lifetime. Later calls only re-apply the stored values. Each component goes through scaledPixels(); a negative spacing (the style default) stays negative.

Parameters
layoutthe layout to scale; nullptr is ignored.

◆ scaleSizeLimits()

void ZoomScaling::scaleSizeLimits ( QWidget * widget)

Makes the minimum and maximum size of widget follow the zoom level.

The first call stores the widget's current minimumSize() and maximumSize() as its zoom level 0 design values (call it after setupUi() or after the widget's own size limit calls), and updates the limits on every zoom change for the widget's lifetime. Later calls only re-apply the stored values. Each component goes through scaledSizeLimit(). Do not use it on a widget that writes its own size limits at runtime (an animated AccordionFrame), as the two writers would overwrite each other.

Parameters
widgetthe widget to scale; nullptr is ignored.

◆ scaleStyleSheetLengths()

QString ZoomScaling::scaleStyleSheetLengths ( const QString & qss,
qreal factor )

Scales the pixel lengths of a stylesheet by factor.

Qt stylesheets only support absolute px/pt units (no relative em/%), so themed text and the lengths around it (heights, radii, padding, margins, sizes) are scaled here to follow the rest of the UI:

  • the size in "font:" / "font-size:" values, px and pt, always;
  • every other "Npx" length in a declaration, through scaledPixels(), except 0 and 1 (resets and hairline borders keep their value). Text inside comments and url(...) is left alone. No-op at a factor of 1.0.