diff options
| author | Jordan Wiens <github@psifertex.com> | 2025-12-19 14:18:19 -0500 |
|---|---|---|
| committer | Jordan Wiens <github@psifertex.com> | 2025-12-19 15:20:22 -0500 |
| commit | dbdf3381e2dd32527cffaca6081fc5a9913f1cc7 (patch) | |
| tree | 4f10dc3101700a63f7e83a087e69b5b1659fb61a /examples/triage/strings.cpp | |
| parent | 1cabd2def9da8ee106be26308b96a2a91cd92a2f (diff) | |
triage view responsive layout
Diffstat (limited to 'examples/triage/strings.cpp')
| -rw-r--r-- | examples/triage/strings.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/triage/strings.cpp b/examples/triage/strings.cpp index 269f747a..a5661139 100644 --- a/examples/triage/strings.cpp +++ b/examples/triage/strings.cpp @@ -3,6 +3,9 @@ #include <QtGui/QClipboard> #include <QtGui/QGuiApplication> #include <QtCore/QStringList> +#include <QtCore/QEvent> +#include <QtCore/QTimer> +#include <QtWidgets/QHeaderView> #include "strings.h" #include "view.h" #include "fontsettings.h" @@ -203,12 +206,39 @@ StringsTreeView::StringsTreeView(StringsWidget* parent, TriageView* view, Binary setFont(getMonospaceFont(this)); + // Set column resize modes - use Interactive to avoid O(n) recalculation on every update + header()->setSectionResizeMode(QHeaderView::Interactive); + header()->setSectionResizeMode(2, QHeaderView::Stretch); // String column stretches to fill + + updateColumnWidths(); + connect(selectionModel(), &QItemSelectionModel::currentChanged, this, &StringsTreeView::stringSelected); connect(this, &QTreeView::doubleClicked, this, &StringsTreeView::stringDoubleClicked); m_actionHandler.bindAction("Copy", UIAction([this]() { copySelection(); }, [this]() { return canCopySelection(); })); } + +void StringsTreeView::updateColumnWidths() +{ + // Size address and length columns based on their headers, not contents + header()->resizeSection(0, header()->sectionSizeHint(0) + 20); + header()->resizeSection(1, header()->sectionSizeHint(1) + 20); +} + + +bool StringsTreeView::event(QEvent* event) +{ + // Update column widths when font or style changes (e.g., UI scale change) + if (event->type() == QEvent::FontChange || event->type() == QEvent::StyleChange) + { + // Defer update until after Qt recalculates font metrics + QTimer::singleShot(0, this, &StringsTreeView::updateColumnWidths); + } + return QTreeView::event(event); +} + + void StringsTreeView::copySelection() { if (!model() || !selectionModel()) |
