From ae398535071856c436562d18fabd431fe577e56e Mon Sep 17 00:00:00 2001 From: phyrophone <255566614+phyrophone@users.noreply.github.com> Date: Fri, 8 May 2026 17:52:28 +0200 Subject: [PATCH 1/2] always update graph tooltip update the text of the tooltip even when not moving the tooltip --- src/perf/graphwidget.cpp | 68 +++++++++++++++++++++++----------------- src/perf/graphwidget.h | 2 ++ 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/perf/graphwidget.cpp b/src/perf/graphwidget.cpp index 7507cec..ee92a5a 100644 --- a/src/perf/graphwidget.cpp +++ b/src/perf/graphwidget.cpp @@ -275,6 +275,9 @@ void GraphWidget::paintEvent(QPaintEvent * /*event*/) p.setPen(QPen(hover, 1)); p.drawLine(QPointF(x, contentTop), QPointF(x, contentBottom)); } + + if (this->m_isHovered) + updateTooltip(); } void GraphWidget::mouseMoveEvent(QMouseEvent *event) @@ -296,41 +299,14 @@ void GraphWidget::mouseMoveEvent(QMouseEvent *event) this->update(oldRect.united(this->hoverLineRect(this->m_hoverSlot))); } - if (this->m_hoverTooltipEnabled && slotChanged) - { - const int idx1 = sampleIndexForSlot(this->m_data ? this->m_data->Size() : 0, slot, sampleCount); - const int idx2 = sampleIndexForSlot(this->m_overlayData ? this->m_overlayData->Size() : 0, slot, sampleCount); - - if (idx1 >= 0 || idx2 >= 0) - { - QString tip; - if (idx1 >= 0) - tip += tr("%1: %2").arg(this->m_primaryName, this->formatValue(this->m_data->At(idx1))); - if (idx2 >= 0) - { - if (!tip.isEmpty()) - tip += "\n"; - tip += tr("%1: %2").arg(this->m_secondaryName, this->formatValue(this->m_overlayData->At(idx2))); - } - const int secAgo = sampleCount - 1 - slot; - if (!tip.isEmpty()) - tip += tr("\n%1 s ago").arg(secAgo); -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - QToolTip::showText(event->globalPosition().toPoint(), tip, this); -#else - QToolTip::showText(event->globalPos(), tip, this); -#endif - } else - { - QToolTip::hideText(); - } - } + this->m_isHovered = true; QWidget::mouseMoveEvent(event); } void GraphWidget::leaveEvent(QEvent *event) { + this->m_isHovered = false; const QRect oldRect = this->hoverLineRect(this->m_hoverSlot); this->m_hoverSlot = -1; if (this->m_hoverTooltipEnabled) @@ -394,3 +370,37 @@ QString GraphWidget::formatValue(double v) const return QString::number(v, 'f', 2); } } + +void GraphWidget::updateTooltip() +{ + if (this->m_hoverTooltipEnabled) + { + const int sampleCount = qMax(2, this->m_sampleCapacity); + const double stepX = static_cast(qMax(1, this->width())) / static_cast(sampleCount - 1); + const double mouseX = mapFromGlobal(QCursor::pos()).x(); + const int slot = qBound(0, static_cast(std::lround(mouseX / stepX)), sampleCount - 1); + + const int idx1 = sampleIndexForSlot(this->m_data ? this->m_data->Size() : 0, slot, sampleCount); + const int idx2 = sampleIndexForSlot(this->m_overlayData ? this->m_overlayData->Size() : 0, slot, sampleCount); + + if (idx1 >= 0 || idx2 >= 0) + { + QString tip; + if (idx1 >= 0) + tip += tr("%1: %2").arg(this->m_primaryName, this->formatValue(this->m_data->At(idx1))); + if (idx2 >= 0) + { + if (!tip.isEmpty()) + tip += "\n"; + tip += tr("%1: %2").arg(this->m_secondaryName, this->formatValue(this->m_overlayData->At(idx2))); + } + const int secAgo = sampleCount - 1 - slot; + if (!tip.isEmpty()) + tip += tr("\n%1 s ago").arg(secAgo); + QToolTip::showText(QCursor::pos(), tip, this); + } else + { + QToolTip::hideText(); + } + } +} diff --git a/src/perf/graphwidget.h b/src/perf/graphwidget.h index 9f416db..81b9b6e 100644 --- a/src/perf/graphwidget.h +++ b/src/perf/graphwidget.h @@ -116,6 +116,7 @@ namespace Perf bool m_gridEnabled { true }; int m_sampleCapacity { 60 }; ///< Matches the default history window in seconds. int m_historyTick { 0 }; ///< Advances as samples arrive; used for grid phase. + bool m_isHovered { false }; int m_hoverSlot { -1 }; bool m_hoverLineEnabled { true }; bool m_hoverTooltipEnabled { true }; @@ -131,6 +132,7 @@ namespace Perf QRect hoverLineRect(int slot) const; static int sampleIndexForSlot(int size, int slot, int sampleCount); QString formatValue(double v) const; + void updateTooltip(); }; } // namespace Perf From 3852f87920d1c025d35eb030050be1c3ff628776 Mon Sep 17 00:00:00 2001 From: phyrophone <255566614+phyrophone@users.noreply.github.com> Date: Fri, 8 May 2026 23:43:08 +0200 Subject: [PATCH 2/2] remove conflicting graph tooltip the tooltip is being set both by this line and by graphwidget.cpp, causing the tooltip's text to flicker back and forth. --- src/perf/gpudetailwidget.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/perf/gpudetailwidget.cpp b/src/perf/gpudetailwidget.cpp index e88074c..7294511 100644 --- a/src/perf/gpudetailwidget.cpp +++ b/src/perf/gpudetailwidget.cpp @@ -112,7 +112,6 @@ GpuDetailWidget::GpuDetailWidget(QWidget *parent) : QWidget(parent), ui(new Ui:: configureGraph(this->ui->copyBwGraphWidget); this->ui->copyBwGraphWidget->SetSeriesNames(tr("TX"), tr("RX")); this->ui->copyBwGraphWidget->SetValueFormat(GraphWidget::ValueFormat::BytesPerSec); - this->ui->copyBwGraphWidget->setToolTip(tr("Copy bandwidth: light trace = TX, dark trace = RX")); UIHelper::EnableCopyWidgetContextMenu(this->ui->copyBwGraphWidget); UIHelper::EnableCopyLabelContextMenu(this->ui->utilValueLabel);