Skip to content

Commit 012515c

Browse files
committed
[labeling] When changing font families, reset to correct regular/book
style if current style is not available Previously the font would be reset to the first style alphabetically, usually 'Bold'. Now it correctly resets to the standard font style.
1 parent c1658fb commit 012515c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/gui/qgstextformatwidget.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,13 +983,21 @@ void QgsTextFormatWidget::populateFontCapitalsComboBox()
983983
void QgsTextFormatWidget::populateFontStyleComboBox()
984984
{
985985
mFontStyleComboBox->clear();
986-
Q_FOREACH ( const QString &style, mFontDB.styles( mRefFont.family() ) )
986+
QStringList styles = mFontDB.styles( mRefFont.family() );
987+
Q_FOREACH ( const QString &style, styles )
987988
{
988989
mFontStyleComboBox->addItem( style );
989990
}
990991

992+
QString targetStyle = mFontDB.styleString( mRefFont );
993+
if ( !styles.contains( targetStyle ) )
994+
{
995+
QFont f = QFont( mRefFont.family() );
996+
targetStyle = QFontInfo( f ).styleName();
997+
mRefFont.setStyleName( targetStyle );
998+
}
991999
int curIndx = 0;
992-
int stylIndx = mFontStyleComboBox->findText( mFontDB.styleString( mRefFont ) );
1000+
int stylIndx = mFontStyleComboBox->findText( targetStyle );
9931001
if ( stylIndx > -1 )
9941002
{
9951003
curIndx = stylIndx;

0 commit comments

Comments
 (0)