Skip to content

Commit

Permalink
Revise map tip cursor offset calculations to better handle hidpi screens
Browse files Browse the repository at this point in the history
Fixes #28337
  • Loading branch information
nyalldawson committed Jul 29, 2019
1 parent 5e0b532 commit 26eaba0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/gui/qgsmaptip.cpp
Expand Up @@ -146,8 +146,18 @@ void QgsMapTip::showMapTip( QgsMapLayer *pLayer,

QgsDebugMsg( tipHtml );

mWidget->move( pixelPosition.x() + Qgis::UI_SCALE_FACTOR * 15,
pixelPosition.y() );
int cursorOffset = 0;
// attempt to shift the tip away from the cursor.
if ( QgsApplication::instance() )
{
// The following calculations are taken
// from QgsApplication::getThemeCursor, and are used to calculate the correct cursor size
// for both hi-dpi and non-hi-dpi screens.
double scale = Qgis::UI_SCALE_FACTOR * QgsApplication::instance()->fontMetrics().height() / 32.0;
cursorOffset = static_cast< int >( std::ceil( scale * 32 ) );
}

mWidget->move( pixelPosition.x() + cursorOffset, pixelPosition.y() );

mWebView->setHtml( tipHtml );
lastTipText = tipText;
Expand Down

0 comments on commit 26eaba0

Please sign in to comment.