Skip to content

Commit 90aa18a

Browse files
committed
Fix #9393, impossible to select 'regular' font style for labels
- While ostensibly fixes the issue, there is still a flaw with QFontDatabase.styleString() returning generic style names
1 parent d12e08e commit 90aa18a

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/core/qgsfontutils.cpp

+6-13
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,7 @@ bool QgsFontUtils::updateFontViaStyle( QFont& f, const QString& fontstyle, bool
110110
if ( !fallback )
111111
{
112112
// does the font even have the requested style?
113-
bool hasstyle = false;
114-
foreach ( const QString &style, fontDB.styles( f.family() ) )
115-
{
116-
if ( style == fontstyle )
117-
{
118-
hasstyle = true;
119-
break;
120-
}
121-
}
122-
113+
bool hasstyle = fontFamilyHasStyle( f.family(), fontstyle );
123114
if ( !hasstyle )
124115
{
125116
return false;
@@ -129,16 +120,18 @@ bool QgsFontUtils::updateFontViaStyle( QFont& f, const QString& fontstyle, bool
129120
// is the font's style already the same as requested?
130121
if ( fontstyle == fontDB.styleString( f ) )
131122
{
132-
return true;
123+
return false;
133124
}
134125

135-
int defaultSize = QApplication::font().pointSize(); // QFontDatabase::font() needs an integer for size
126+
QFont appfont = QApplication::font();
127+
int defaultSize = appfont.pointSize(); // QFontDatabase::font() needs an integer for size
136128

137129
QFont styledfont;
138130
bool foundmatch = false;
139131

132+
// if fontDB.font() fails, it returns the default app font; but, that may be the target style
140133
styledfont = fontDB.font( f.family(), fontstyle, defaultSize );
141-
if ( QApplication::font() != styledfont )
134+
if ( appfont != styledfont || fontstyle != fontDB.styleString( f ) )
142135
{
143136
foundmatch = true;
144137
}

0 commit comments

Comments
 (0)