Commit 9ccec8c9 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

Make sure the size of the menu title is big enough

If we're changing the font size when painting we need to change the
fontSize when calculating the contents size too otherwise you end up
with things that don't fit

BUGS: 450333
(cherry picked from commit dc7b58c1)
parent 23dd3cd4
Pipeline #138323 passed with stage
in 2 minutes and 58 seconds
......@@ -2916,10 +2916,24 @@ namespace Breeze
}
//______________________________________________________________
QSize Style::toolButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const
static QStyleOptionToolButton toolButtonMenuTitleOption( const QStyleOptionToolButton &option )
{
QStyleOptionToolButton copy = QStyleOptionToolButton( option );
copy.font.setBold( false );
copy.state = Style::State_Enabled;
return copy;
}
static QFont menuTitleFont( const QStyleOptionToolButton &option )
{
auto font = option.font;
font.setPointSize( qRound( font.pointSize() * 1.1 ) );
return font;
}
//______________________________________________________________
QSize Style::toolButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const
{
// cast option and check
const auto toolButtonOption = qstyleoption_cast<const QStyleOptionToolButton*>( option );
if( !toolButtonOption ) return contentsSize;
......@@ -2927,6 +2941,13 @@ namespace Breeze
// copy size
QSize size = contentsSize;
if( isMenuTitle( widget ) )
{
const QStyleOptionToolButton copy = toolButtonMenuTitleOption( *toolButtonOption );
const QFontMetrics fm(menuTitleFont(copy));
size.setWidth(std::max(size.width(), fm.size(Qt::TextShowMnemonic, copy.text).width()));
}
// get relevant state flags
const State& state( option->state );
const bool autoRaise( state & State_AutoRaise );
......@@ -6363,9 +6384,7 @@ namespace Breeze
if( isMenuTitle )
{
// copy option to adjust state, and set font as not-bold
QStyleOptionToolButton copy( *toolButtonOption );
copy.font.setBold( false );
copy.state = State_Enabled;
const QStyleOptionToolButton copy = toolButtonMenuTitleOption( *toolButtonOption );
// render
renderMenuTitle( &copy, painter, widget );
......@@ -7097,9 +7116,7 @@ namespace Breeze
// render text in the center of the rect
// icon is discarded on purpose
// make text the same size as a level 4 heading so it looks more title-ish
auto font = option->font;
font.setPointSize( qRound( font.pointSize() * 1.1 ) );
painter->setFont( font );
painter->setFont( menuTitleFont(*option) );
const auto contentsRect = insideMargin( option->rect, Metrics::MenuItem_MarginWidth, Metrics::MenuItem_MarginHeight );
drawItemText( painter, contentsRect, Qt::AlignCenter, palette, true, option->text, QPalette::WindowText );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment