Skip to main content

LayoutSanityChecker

LayoutSanityChecker

Runtime layout constraint checker for Qt widget trees. More…

#include <LayoutSanityChecker.hpp>

Inherits from QObject

Public Functions

Name
LayoutSanityChecker(QObject * parent =[nullptr])
~LayoutSanityChecker() override =default
std::vector< LayoutViolation > getViolations(QWidget * root)
Collect all layout violations under root (including root itself).
QString widgetPath(QWidget const * widget)
Build a diagnostic ancestry path for a widget.

Protected Functions

Name
bool eventFilter(QObject * obj, QEvent * event) override

Detailed Description

class LayoutSanityChecker;

Runtime layout constraint checker for Qt widget trees.

Two usage modes:

  1. Global monitor — construct an instance (typically in main.cpp under #ifndef NDEBUG). It installs itself as an event filter on qApp and logs violations via qWarning whenever layouts settle after a resize or layout request on a top-level window.
  2. Static query — call getViolations(root) from a Catch2 test to collect all violations under a widget subtree. No event filter needed.

Public Functions Documentation

function LayoutSanityChecker

explicit LayoutSanityChecker(
    QObject * parent =nullptr
)

function ~LayoutSanityChecker

~LayoutSanityChecker() override =default

function getViolations

static std::vector< LayoutViolation > getViolations(
    QWidget * root
)

Collect all layout violations under root (including root itself).

Parameters:

  • root Widget subtree to inspect

Return: Vector of violations found (empty if layout is healthy)

Only visible widgets are checked. Invisible widgets and their children are skipped.

function widgetPath

static QString widgetPath(
    QWidget const * widget
)

Build a diagnostic ancestry path for a widget.

Walks up the parent chain, using objectName if set or the meta-object class name otherwise. Example: “MainWindow/DockWidget/ColormapControls/vmax_spin”

Protected Functions Documentation

function eventFilter

bool eventFilter(
    QObject * obj,
    QEvent * event
) override

Updated on 2026-11-13 at 20:25:40 +0000