Wireshark 4.7.2
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
AdaptiveToolButton Class Reference

A flat, icon-only tool button whose footprint hugs its icon and whose icon scales with the application zoom. More...

#include <adaptive_tool_button.h>

Inheritance diagram for AdaptiveToolButton:

Public Member Functions

 AdaptiveToolButton (QWidget *parent=nullptr)
void setBaseIconSize (const QSize &size)
 Sets the logical icon size at zoom 1.0.
QSize baseIconSize () const
 The logical icon size at zoom 1.0.
void setIconPadding (int padding)
 Sets the symmetric padding (px) added around the icon in the size hint. Not zoom-scaled, so it stays a crisp hairline gap at any zoom.
int iconPadding () const
 The symmetric padding (px) around the icon.
QSize sizeHint () const override
 Icon footprint plus padding; tight, ignoring style margins.
QSize minimumSizeHint () const override
 Same as sizeHint(): the button never shrinks below its glyph.

Detailed Description

A flat, icon-only tool button whose footprint hugs its icon and whose icon scales with the application zoom.

AdaptiveToolButton exists for inline use inside a line edit's content area (bookmark / clear / apply / history affordances). It solves two problems the native QLineEdit side-action button could not:

  1. Tight box. A plain QToolButton (and the internal QLineEditIconButton) sizes itself from the style, which pads the icon with fixed dead space (the side-widget box is PM_SmallIconSize + 6, leaving ~3px each side and a centred glyph). This widget overrides sizeHint()/minimumSizeHint() to return exactly iconSize + 2*iconPadding, so the host can place a box that hugs the glyph instead of a fixed, oversized one.
  2. Zoom-aware icon. The icon is sized from a base (logical) size taken at zoom 1.0 and scaled by FontManager::zoomFactor(), recomputed whenever the zoom changes. The glyph therefore grows and shrinks with the surrounding text instead of staying a fixed pixel size.

It deliberately does NOT position itself. Placement within the host (anchoring, text-margin reservation, dividers) is the container's job; this widget only reports how much room it needs. The flat appearance (no frame or fill) is supplied by the global AdaptiveToolButton rule in application.qss.

Defaults: the base icon size is the style's PM_SmallIconSize (so the platform icon contract is honoured unless a caller sets something else, e.g. a wide apply glyph via setBaseIconSize(QSize(24, 14))), and the icon padding is the style's PM_DefaultFrameWidth (~1px).

Member Function Documentation

◆ setBaseIconSize()

void AdaptiveToolButton::setBaseIconSize ( const QSize & size)

Sets the logical icon size at zoom 1.0.

The effective icon size (QToolButton::iconSize()) is this value scaled by the current zoom factor; it updates automatically on zoom changes. Pass a non-square size for glyphs that are not 1:1 (e.g. the apply chevron).

If never set, the base size defaults to the style's PM_SmallIconSize.

◆ setIconPadding()

void AdaptiveToolButton::setIconPadding ( int padding)

Sets the symmetric padding (px) added around the icon in the size hint. Not zoom-scaled, so it stays a crisp hairline gap at any zoom.

If never set, the padding defaults to the style's PM_DefaultFrameWidth (~1px).


The documentation for this class was generated from the following files: