Skip to content

Commit

Permalink
Followup 2ec0513, fix incorrect styling of some GUI elements
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 31, 2018
1 parent 84d155e commit 0d52194
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/gui/qgsproxystyle.cpp
Expand Up @@ -24,8 +24,12 @@ QgsProxyStyle::QgsProxyStyle( QWidget *parent )
: QProxyStyle( nullptr ) // no base style yet - it transfers ownership, so we need a NEW QStyle object for the base style
{
// get application style
QString appStyle = QApplication::style()->objectName();
if ( !appStyle.isEmpty() )
const QString appStyle = QApplication::style()->objectName();
if ( appStyle == QLatin1String( "QgsAppStyle" ) )
{
setBaseStyle( static_cast< QgsAppStyle * >( QApplication::style() )->clone() );
}
else if ( !appStyle.isEmpty() )
{
if ( QStyle *style = QStyleFactory::create( appStyle ) )
setBaseStyle( style );
Expand All @@ -43,12 +47,15 @@ QgsProxyStyle::QgsProxyStyle( QWidget *parent )

QgsAppStyle::QgsAppStyle( const QString &base )
: QProxyStyle( nullptr ) // no base style yet - it transfers ownership, so we need a NEW QStyle object for the base style
, mBaseStyle( base )
{
if ( !base.isEmpty() )
if ( !mBaseStyle.isEmpty() )
{
if ( QStyle *style = QStyleFactory::create( base ) )
if ( QStyle *style = QStyleFactory::create( mBaseStyle ) )
setBaseStyle( style );
}

setObjectName( QStringLiteral( "QgsAppStyle" ) );
}

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

QProxyStyle *QgsAppStyle::clone()
{
return new QgsAppStyle( mBaseStyle );
}

///@endcond
10 changes: 10 additions & 0 deletions src/gui/qgsproxystyle.h
Expand Up @@ -57,6 +57,16 @@ class GUI_EXPORT QgsAppStyle : public QProxyStyle
explicit QgsAppStyle( const QString &base );
QPixmap generatedIconPixmap( QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt ) const override;

/**
* Returns a new QgsAppStyle instance, with the same base style as this instance.
*
* Caller takes ownership of the returned object.
*/
QProxyStyle *clone() SIP_FACTORY;

private:

QString mBaseStyle;
};

#endif
Expand Down

0 comments on commit 0d52194

Please sign in to comment.