Skip to content

Commit 22418b4

Browse files
nyalldawsonnirvn
authored andcommittedJan 18, 2019
Followup 2ec0513, fix incorrect styling of some GUI elements
1 parent b55b0ec commit 22418b4

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed
 

‎src/gui/qgsproxystyle.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ QgsProxyStyle::QgsProxyStyle( QWidget *parent )
2424
: QProxyStyle( nullptr ) // no base style yet - it transfers ownership, so we need a NEW QStyle object for the base style
2525
{
2626
// get application style
27-
QString appStyle = QApplication::style()->objectName();
28-
if ( !appStyle.isEmpty() )
27+
const QString appStyle = QApplication::style()->objectName();
28+
if ( appStyle == QLatin1String( "QgsAppStyle" ) )
29+
{
30+
setBaseStyle( static_cast< QgsAppStyle * >( QApplication::style() )->clone() );
31+
}
32+
else if ( !appStyle.isEmpty() )
2933
{
3034
if ( QStyle *style = QStyleFactory::create( appStyle ) )
3135
setBaseStyle( style );
@@ -43,12 +47,15 @@ QgsProxyStyle::QgsProxyStyle( QWidget *parent )
4347

4448
QgsAppStyle::QgsAppStyle( const QString &base )
4549
: QProxyStyle( nullptr ) // no base style yet - it transfers ownership, so we need a NEW QStyle object for the base style
50+
, mBaseStyle( base )
4651
{
47-
if ( !base.isEmpty() )
52+
if ( !mBaseStyle.isEmpty() )
4853
{
49-
if ( QStyle *style = QStyleFactory::create( base ) )
54+
if ( QStyle *style = QStyleFactory::create( mBaseStyle ) )
5055
setBaseStyle( style );
5156
}
57+
58+
setObjectName( QStringLiteral( "QgsAppStyle" ) );
5259
}
5360

5461
QPixmap QgsAppStyle::generatedIconPixmap( QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt ) const
@@ -74,4 +81,9 @@ QPixmap QgsAppStyle::generatedIconPixmap( QIcon::Mode iconMode, const QPixmap &p
7481
return QProxyStyle::generatedIconPixmap( iconMode, pixmap, opt );
7582
}
7683

84+
QProxyStyle *QgsAppStyle::clone()
85+
{
86+
return new QgsAppStyle( mBaseStyle );
87+
}
88+
7789
///@endcond

‎src/gui/qgsproxystyle.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ class GUI_EXPORT QgsAppStyle : public QProxyStyle
5757
explicit QgsAppStyle( const QString &base );
5858
QPixmap generatedIconPixmap( QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt ) const override;
5959

60+
/**
61+
* Returns a new QgsAppStyle instance, with the same base style as this instance.
62+
*
63+
* Caller takes ownership of the returned object.
64+
*/
65+
QProxyStyle *clone() SIP_FACTORY;
66+
67+
private:
68+
69+
QString mBaseStyle;
6070
};
6171

6272
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.