跳转至

cf::ui::base::device::CanvasUnitHelper

Helper for converting between canvas units and device pixels. More...

#include <device_pixel.h>

Public Types

Name
enum class BreakPoint { Compact, Medium, Expanded}
Window width breakpoints for responsive layouts.

Public Functions

Name
CanvasUnitHelper(constqreal devicePixelRatio)
Constructs a CanvasUnitHelper with the specified device pixel ratio.
qreal dpToPx(qreal dp) const
Converts device-independent pixels to physical pixels.
qreal spToPx(qreal sp) const
Converts scalable pixels to physical pixels.
qreal pxToDp(qreal px) const
Converts physical pixels to device-independent pixels.
qreal dpi() const
Returns the device pixel ratio.
BreakPoint breakPoint(qreal widthDp)
Determines the breakpoint category for a given width.

Detailed Description

struct cf::ui::base::device::CanvasUnitHelper;

Helper for converting between canvas units and device pixels.

Note: Not thread-safe unless externally synchronized.

Provides conversion functions for device-independent pixels (dp), scalable pixels (sp), and physical pixels based on the device pixel ratio.

CanvasUnitHelper helper(2.0);
qreal pixels = helper.dpToPx(16.0); // Converts 16dp to pixels

Public Types Documentation

enum BreakPoint

Enumerator Value Description
Compact Compact width: < 600dp.
Medium Medium width: 600dp - 839dp.
Expanded Expanded width: >= 840dp.

Window width breakpoints for responsive layouts.

Defines breakpoints for different screen size categories following Material Design guidelines.

Public Functions Documentation

function CanvasUnitHelper

CanvasUnitHelper(
    constqreal devicePixelRatio
)

Constructs a CanvasUnitHelper with the specified device pixel ratio.

Parameters:

  • devicePixelRatio The device pixel ratio (e.g., 1.0, 2.0, 3.0).

Exceptions:

  • None.

Return: None (constructor).

Since: 0.1

Note: None.

Warning: None.

function dpToPx

qreal dpToPx(
    qreal dp
) const

Converts device-independent pixels to physical pixels.

Parameters:

  • dp Value in device-independent pixels.

Exceptions:

  • None

Return: Value in physical pixels.

Since: 0.1

Note: None

Warning: None

function spToPx

qreal spToPx(
    qreal sp
) const

Converts scalable pixels to physical pixels.

Parameters:

  • sp Value in scalable pixels.

Exceptions:

  • None

Return: Value in physical pixels.

Since: 0.1

Note: None

Warning: None

function pxToDp

qreal pxToDp(
    qreal px
) const

Converts physical pixels to device-independent pixels.

Parameters:

  • px Value in physical pixels.

Exceptions:

  • None

Return: Value in device-independent pixels.

Since: 0.1

Note: None

Warning: None

function dpi

qreal dpi() const

Returns the device pixel ratio.

Exceptions:

  • None

Return: The device pixel ratio.

Since: 0.1

Note: None

Warning: None

function breakPoint

BreakPoint breakPoint(
    qreal widthDp
)

Determines the breakpoint category for a given width.

Parameters:

  • widthDp Width in device-independent pixels.

Exceptions:

  • None

Return: The breakpoint category for the specified width.

Since: 0.1

Note: None

Warning: None


Updated on 2026-03-09 at 10:14:00 +0000