Skip to content

Commit 346ab60

Browse files
committedNov 27, 2017
[hidpi] Auto-scale cursors based on DPIs
This should work well on different DPI screens. Still needs some testing on the various platforms.
1 parent 7ae8e16 commit 346ab60

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed
 

‎images/themes/default/cursors/mSampler.svg

Lines changed: 13 additions & 11 deletions
Loading

‎python/core/qgsapplication.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ Returns the path to the default theme directory.
360360
%Docstring
361361
Helper to get a theme cursor. It will fall back to the
362362
default theme if the active theme does not have the required icon.
363+
Cursors are automatically scaled to look like a 16px cursor on 96dpi
364+
screens.
363365
:rtype: QCursor
364366
%End
365367

‎src/core/qgsapplication.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,7 @@ QCursor QgsApplication::getThemeCursor( const Cursor &cursor )
487487
if ( app && app->mCursorCache.contains( cursor ) )
488488
return app->mCursorCache.value( cursor );
489489

490-
// Cursor are supposed to be 32x32 as it seems to be the
491-
// most cross-platform size
492-
// If we want to make this size user-configurable or make
493-
// a better guess: we might use fontMetrics
490+
// All calculations are done on 32x32 icons
494491
// Defaults to center, individual cursors may override
495492
int activeX = 16;
496493
int activeY = 16;
@@ -520,7 +517,7 @@ QCursor QgsApplication::getThemeCursor( const Cursor &cursor )
520517
break;
521518
case Sampler:
522519
activeX = 0;
523-
activeY = 0;
520+
activeY = 32;
524521
name = QStringLiteral( "mSampler.svg" );
525522
break;
526523
// No default
@@ -533,7 +530,9 @@ QCursor QgsApplication::getThemeCursor( const Cursor &cursor )
533530
// Check if an icon exists for this cursor (the O.S. default cursor will be used if it does not)
534531
if ( ! icon.isNull( ) )
535532
{
536-
_cursor = QCursor( icon.pixmap( 32, 32 ), activeX, activeY );
533+
// Apply scaling
534+
float scale( ( float ) app->fontMetrics().height() / 32 );
535+
_cursor = QCursor( icon.pixmap( std::ceil( scale * 32 ), std::ceil( scale * 32 ) ), std::ceil( scale * activeX ), std::ceil( scale * activeY ) );
537536
}
538537
if ( app )
539538
app->mCursorCache.insert( cursor, _cursor );

‎src/core/qgsapplication.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ class CORE_EXPORT QgsApplication : public QApplication
329329
/**
330330
* Helper to get a theme cursor. It will fall back to the
331331
* default theme if the active theme does not have the required icon.
332+
* Cursors are automatically scaled to look like a 16px cursor on 96dpi
333+
* screens.
332334
*/
333335
static QCursor getThemeCursor( const Cursor &cursor );
334336

0 commit comments

Comments
 (0)
Please sign in to comment.