void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant>& opts ) { QString ss = QString( "" ); // QgisApp-wide font QString fontSize = opts.value( "fontPointSize" ).toString(); QgsDebugMsg( QString( "fontPointSize: %1" ).arg( fontSize ) ); if ( fontSize.isEmpty() ) { return; } QString fontFamily = opts.value( "fontFamily" ).toString(); QgsDebugMsg( QString( "fontFamily: %1" ).arg( fontFamily ) ); if ( fontFamily.isEmpty() ) { return; } ss += QString( "* { font: %1pt \"%2\"} " ).arg( fontSize ).arg( fontFamily ); // QGroupBox and QgsCollapsibleGroupBox, mostly for Ubuntu and Mac bool gbxCustom = opts.value( "groupBoxCustom" ).toBool(); QgsDebugMsg( QString( "groupBoxCustom: %1" ).arg( gbxCustom ) ); bool gbxBoldTitle = opts.value( "groupBoxBoldTitle" ).toBool(); QgsDebugMsg( QString( "groupBoxBoldTitle: %1" ).arg( gbxBoldTitle ) ); bool sidebar = opts.value( "sidebarStyle" ).toBool(); if ( gbxCustom || gbxBoldTitle ) { ss += "QGroupBox{"; if ( gbxBoldTitle ) { // doesn't work for QGroupBox::title ss += QString( "color: rgb(%1,%1,%1);" ).arg( mMacStyle ? 25 : 60 ); ss += "font-weight: bold;"; } if ( gbxCustom ) { ss += QString( "background-color: rgba(0,0,0,%1%);" ) .arg( mWinOS && mStyle.startsWith( "windows" ) ? 0 : 3 ); ss += "border: 1px solid rgba(0,0,0,20%);"; ss += "border-radius: 5px;"; ss += "margin-top: 2.5ex;"; ss += QString( "margin-bottom: %1ex;" ).arg( mMacStyle ? 1.5 : 1 ); } ss += "} "; if ( gbxCustom ) { ss += "QGroupBox:flat{"; ss += "background-color: rgba(0,0,0,0);"; ss += "border: rgba(0,0,0,0);"; ss += "} "; ss += "QGroupBox::title{"; ss += "subcontrol-origin: margin;"; ss += "subcontrol-position: top left;"; ss += "margin-left: 6px;"; if ( !( mWinOS && mStyle.startsWith( "windows" ) ) && !mOxyStyle ) { ss += "background-color: rgba(0,0,0,0);"; } ss += "} "; } } if ( sidebar ) { QString style = "QListWidget#mOptionsListWidget {" " background-color: rgb(69, 69, 69, 220);" " outline: 0;" "}" "QListWidget#mOptionsListWidget::item {" " color: white;" " padding: 3px;" "}" "QListWidget#mOptionsListWidget::item::selected {" " color: black;" " background-color:palette(Window);" " padding-right: 0px;" "}"; ss += style; } //fix background issue for gnome desktop if ( mLinuxOS && mGtkStyle && !sidebar ) { ss += "QListWidget#mOptionsListWidget{"; ss += "background-color: white;"; ss += "} "; } // Fix selection color on loosing focus (Windows) const QPalette palette = qApp->palette(); ss += QString( "QTableView {" "selection-background-color: %1;" "selection-color: %2;" "}" ) .arg( palette.highlight().color().name() ) .arg( palette.highlightedText().color().name() ); QgsDebugMsg( QString( "Stylesheet built: %1" ).arg( ss ) ); emit appStyleSheetChanged( ss ); }
void QgisAppStyleSheet::buildStyleSheet( const QMap<QString, QVariant> &opts ) { QString ss; // QgisApp-wide font QString fontSize = opts.value( QStringLiteral( "fontPointSize" ) ).toString(); QgsDebugMsg( QStringLiteral( "fontPointSize: %1" ).arg( fontSize ) ); if ( fontSize.isEmpty() ) { return; } QString fontFamily = opts.value( QStringLiteral( "fontFamily" ) ).toString(); QgsDebugMsg( QStringLiteral( "fontFamily: %1" ).arg( fontFamily ) ); if ( fontFamily.isEmpty() ) { return; } const QString defaultSize = QString::number( mDefaultFont.pointSize() ); const QString defaultFamily = mDefaultFont.family(); if ( fontSize != defaultSize || fontFamily != defaultFamily ) ss += QStringLiteral( "* { font: %1pt \"%2\"} " ).arg( fontSize, fontFamily ); // Fix for macOS Qt 5.9+, where close boxes do not show on document mode tab bar tabs // See: https://bugreports.qt.io/browse/QTBUG-61092 // https://bugreports.qt.io/browse/QTBUG-61742 // Setting any stylesheet makes the default close button disappear. // Specifically setting a custom close button temporarily works around issue. // TODO: Remove when regression is fixed (Qt 5.9.3 or 5.10?); though hard to tell, // since we are overriding the default close button image now. if ( mMacStyle ) { ss += QLatin1String( "QTabBar::close-button{ image: url(:/images/themes/default/mIconCloseTab.svg); }" ); ss += QLatin1String( "QTabBar::close-button:hover{ image: url(:/images/themes/default/mIconCloseTabHover.svg); }" ); } // QGroupBox and QgsCollapsibleGroupBox, mostly for Ubuntu and Mac bool gbxCustom = opts.value( QStringLiteral( "groupBoxCustom" ) ).toBool(); QgsDebugMsg( QStringLiteral( "groupBoxCustom: %1" ).arg( gbxCustom ) ); ss += QLatin1String( "QGroupBox{" ); // doesn't work for QGroupBox::title ss += QStringLiteral( "color: rgb(%1,%1,%1);" ).arg( mMacStyle ? 25 : 60 ); ss += QLatin1String( "font-weight: bold;" ); if ( gbxCustom ) { ss += QStringLiteral( "background-color: rgba(0,0,0,%1%);" ) .arg( mWinOS && mStyle.startsWith( QLatin1String( "windows" ) ) ? 0 : 3 ); ss += QLatin1String( "border: 1px solid rgba(0,0,0,20%);" ); ss += QLatin1String( "border-radius: 5px;" ); ss += QLatin1String( "margin-top: 2.5ex;" ); ss += QStringLiteral( "margin-bottom: %1ex;" ).arg( mMacStyle ? 1.5 : 1 ); } ss += QLatin1String( "} " ); if ( gbxCustom ) { ss += QLatin1String( "QGroupBox:flat{" ); ss += QLatin1String( "background-color: rgba(0,0,0,0);" ); ss += QLatin1String( "border: rgba(0,0,0,0);" ); ss += QLatin1String( "} " ); ss += QLatin1String( "QGroupBox::title{" ); ss += QLatin1String( "subcontrol-origin: margin;" ); ss += QLatin1String( "subcontrol-position: top left;" ); ss += QLatin1String( "margin-left: 6px;" ); if ( !( mWinOS && mStyle.startsWith( QLatin1String( "windows" ) ) ) && !mOxyStyle ) { ss += QLatin1String( "background-color: rgba(0,0,0,0);" ); } ss += QLatin1String( "} " ); } //sidebar style QString style = "QListWidget#mOptionsListWidget {" " background-color: rgb(69, 69, 69, 0);" " outline: 0;" "}" "QFrame#mOptionsListFrame {" " background-color: rgb(69, 69, 69, 220);" "}" "QListWidget#mOptionsListWidget::item {" " color: white;" " padding: 3px;" "}" "QListWidget#mOptionsListWidget::item::selected {" " color: black;" " background-color:palette(Window);" " padding-right: 0px;" "}"; ss += style; // Fix selection color on losing focus (Windows) const QPalette palette = qApp->palette(); ss += QString( "QTableView {" "selection-background-color: %1;" "selection-color: %2;" "}" ) .arg( palette.highlight().color().name(), palette.highlightedText().color().name() ); QString toolbarSpacing = opts.value( QStringLiteral( "toolbarSpacing" ), QString() ).toString(); if ( !toolbarSpacing.isEmpty() ) { bool ok = false; int toolbarSpacingInt = toolbarSpacing.toInt( &ok ); if ( ok ) { ss += QStringLiteral( "QToolBar > QToolButton { padding: %1px; } " ).arg( toolbarSpacingInt ); } } QgsDebugMsg( QStringLiteral( "Stylesheet built: %1" ).arg( ss ) ); emit appStyleSheetChanged( ss ); }