Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
qgstabbarproxystyle: Fix tab size if the font is not overriden
`QgsTabBar::tabSizeHint` computes the size hint for a tab. However it
takes into account the `LabelStyle` font even if the font is not
overriden. This results in a wrong tab size if the tabSize font size
is different from the default font.

This issues is fixed by taking into account the `tabStyle` font only
if the default font is overriden.

Fixes:
78fc3ca

Closes: #53181
  • Loading branch information
ptitjano authored and nyalldawson committed May 23, 2023
1 parent b99a349 commit 01c10ae
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/gui/qgstabbarproxystyle.cpp
Expand Up @@ -83,13 +83,21 @@ QSize QgsTabBar::tabSizeHint( int index ) const
{
if ( mTabBarStyle->tabStyles().contains( index ) )
{
const QSize s = QTabBar::tabSizeHint( index );
const QFontMetrics fm( font() );
const int w = fm.horizontalAdvance( tabText( index ) );
const QFont f = mTabBarStyle->tabStyles().value( index ).font;
const QFontMetrics bfm( f );
const int bw = bfm.horizontalAdvance( tabText( index ) );
return QSize( s.width() - w + bw, s.height() );
const QgsAttributeEditorElement::LabelStyle tabStyle = mTabBarStyle->tabStyles().value( index );
if ( tabStyle.overrideFont )
{
const QSize s = QTabBar::tabSizeHint( index );
const QFontMetrics fm( font() );
const int w = fm.horizontalAdvance( tabText( index ) );
const QFont f = tabStyle.font;
const QFontMetrics bfm( f );
const int bw = bfm.horizontalAdvance( tabText( index ) );
return QSize( s.width() - w + bw, s.height() );
}
else
{
return QTabBar::tabSizeHint( index );
}
}
else
{
Expand Down

0 comments on commit 01c10ae

Please sign in to comment.