Skip to content

Commit d50ccff

Browse files
committedSep 30, 2018
[browser] Fix tiny folder icons on hidpi screens
QStyle::standardPixmap is deprecated and not hi-dpi friendly. Unfortunately, there's no equivalent of QIcon::addPixmap for QIcons themselves -- so it's **impossible** in current Qt API to handle the ON/OFF icon states. Believe me... there's NOOOOOOO way. I've looked. I've tried. It's not possible. This means we have to change the logic for showing open/closed folders in browser. This commit revises the logic to show the open icon for any *populated* folders, regardless of whether they are opened or not.
1 parent 3032af2 commit d50ccff

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed
 

‎python/core/auto_generated/qgsdataitem.sip.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,15 @@ A Collection: logical collection of layers or subcollections, e.g. GRASS locatio
501501

502502
static QIcon iconDir(); // shared icon: open/closed directory
503503
static QIcon iconDataCollection(); // default icon for data collection
504+
505+
protected:
506+
507+
static QIcon openDirIcon();
508+
%Docstring
509+
Shared open directory icon.
510+
511+
.. versionadded:: 3.4
512+
%End
504513
};
505514

506515
class QgsDirectoryItem : QgsDataCollectionItem

‎src/core/qgsdataitem.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ QIcon QgsDataCollectionItem::iconDataCollection()
8989
return QgsApplication::getThemeIcon( QStringLiteral( "/mIconDbSchema.svg" ) );
9090
}
9191

92+
QIcon QgsDataCollectionItem::openDirIcon()
93+
{
94+
static QIcon sIcon;
95+
96+
if ( sIcon.isNull() )
97+
{
98+
// initialize shared icons
99+
QStyle *style = QApplication::style();
100+
sIcon = QIcon( style->standardIcon( QStyle::SP_DirOpenIcon ) );
101+
}
102+
103+
return sIcon;
104+
}
105+
92106
QIcon QgsDataCollectionItem::iconDir()
93107
{
94108
static QIcon sIcon;
@@ -97,7 +111,7 @@ QIcon QgsDataCollectionItem::iconDir()
97111
{
98112
// initialize shared icons
99113
QStyle *style = QApplication::style();
100-
sIcon = QIcon( style->standardPixmap( QStyle::SP_DirClosedIcon ) );
114+
sIcon = QIcon( style->standardIcon( QStyle::SP_DirClosedIcon ) );
101115
sIcon.addPixmap( style->standardPixmap( QStyle::SP_DirOpenIcon ),
102116
QIcon::Normal, QIcon::On );
103117
}
@@ -737,8 +751,15 @@ void QgsDirectoryItem::init()
737751

738752
QIcon QgsDirectoryItem::icon()
739753
{
754+
// still loading? show the spinner
740755
if ( state() == Populating )
741756
return QgsDataItem::icon();
757+
758+
// loaded? show the open dir icon
759+
if ( state() == Populated )
760+
return openDirIcon();
761+
762+
// show the closed dir icon
742763
return iconDir();
743764
}
744765

@@ -1555,6 +1576,8 @@ QgsProjectHomeItem::QgsProjectHomeItem( QgsDataItem *parent, const QString &name
15551576

15561577
QIcon QgsProjectHomeItem::icon()
15571578
{
1579+
if ( state() == Populating )
1580+
return QgsDirectoryItem::icon();
15581581
return QgsApplication::getThemeIcon( QStringLiteral( "mIconQgsProjectFile.svg" ) );
15591582
}
15601583

‎src/core/qgsdataitem.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,14 @@ class CORE_EXPORT QgsDataCollectionItem : public QgsDataItem
522522

523523
static QIcon iconDir(); // shared icon: open/closed directory
524524
static QIcon iconDataCollection(); // default icon for data collection
525+
526+
protected:
527+
528+
/**
529+
* Shared open directory icon.
530+
* \since QGIS 3.4
531+
*/
532+
static QIcon openDirIcon();
525533
};
526534

527535
/**

0 commit comments

Comments
 (0)
Please sign in to comment.