How do I add a badge to a Qt list view?
The badge resolution architecture — how BadgeCache, code_domain,
badge_definition, and badge_mapping fit together — is in
Badge system wiring.
Question
How do I render a new field as a DB-driven pill badge in a Qt list view?
Answer
Four steps; all are required.
1. Add a code domain to dq_badge_system_populate.sql:
PERFORM ores_dq_code_domains_upsert_fn(ores_utility_system_tenant_id_fn(),
'my_domain', 'My Domain', 'Description of the domain.', <next_display_order>);
2. Add badge definitions — one per distinct visual variant:
PERFORM ores_dq_badge_definitions_upsert_fn(ores_utility_system_tenant_id_fn(),
'my_def_code', 'Label', 'Tooltip description.',
'#rrggbb', '#ffffff', 'severity_code', 'badge bg-severity', <next_display_order>);
Severity codes: secondary, info, success, warning, danger, primary.
3. Add badge mappings — one per entity code value:
PERFORM ores_dq_badge_mappings_upsert_fn(ores_utility_system_tenant_id_fn(),
'my_domain', 'entity_code_value', 'my_def_code');
The entity code must match exactly what the Qt model returns for
Qt::DisplayRole on that column (raw DB code or translated display string).
4. Wire the delegate in the entity's ItemDelegate:
paint(): addColumn::MyFieldto the badge column guard; callbadgeCache_->resolve("my_domain", text.toStdString())and apply the returned colours; fall back to default gray onnullptr.sizeHint(): add the same column guard; set minimum height 24 px and a minimum width appropriate for the longest label.
Script
No script — changes are to dq_badge_system_populate.sql and the
entity's ItemDelegate. See Badge system wiring for the full
paint() code template.
Tested by
Manual: re-run the population script against a dev database and open the entity list view to confirm badge colours appear.
See also
- Badge system wiring — architecture,
BadgeCacheAPI, and worked example. - Entity controller pattern — the delegate's place in the entity UI stack.