From 6e6881e2117c5aaa4f425635c639483d1f3a3857 Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Tue, 18 Nov 2014 19:02:29 +0000 Subject: [PATCH] DecodeTrace: Make tool tips use mapToGlobal() of the view's viewport --- pv/view/decodetrace.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index e290e55..5ee8645 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -45,6 +45,7 @@ extern "C" { #include #include #include +#include #include #include @@ -606,18 +607,29 @@ void DecodeTrace::show_hover_annotation() assert(_view); assert(_row_height); - assert(_text_height); if (!ann.isEmpty()) { const int hover_row = get_row_at_hover_point(); + QFontMetrics m(QToolTip::font()); + const QRect text_size = m.boundingRect(QRect(), 0, ann); + + // This is OS-specific and unfortunately we can't query it, so + // use an approximation to at least try to minimize the error. + const int padding = 8; + // Make sure the tool tip doesn't overlap with the mouse cursor. // If it did, the tool tip would constantly hide and re-appear. + // We also push it up by one row so that it appears above the + // decode trace, not below. QPoint hp = _view->hover_point(); - hp.setY(get_y() - (_row_height/2) + - (hover_row * _row_height) - _text_height); - QToolTip::showText(_view->mapToGlobal(hp), ann); + hp.setX(hp.x() - (text_size.width() / 2) - padding); + + hp.setY(get_y() - (_row_height / 2) + (hover_row * _row_height) + - _row_height - text_size.height()); + + QToolTip::showText(_view->viewport()->mapToGlobal(hp), ann); } else hide_hover_annotation(); } -- 2.30.2