mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-04 09:00:44 +00:00
Elide tool button text if the button isn't large enough
This commit is contained in:
@@ -482,9 +482,28 @@ void RDTweakedNativeStyle::drawControl(ControlElement control, const QStyleOptio
|
||||
proxy()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, iconRect),
|
||||
Qt::AlignCenter, pixmap);
|
||||
|
||||
proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, textRect), textFlags,
|
||||
toolopt->palette, toolopt->state & State_Enabled, toolopt->text,
|
||||
QPalette::ButtonText);
|
||||
// elide text from the right if there's not enough space
|
||||
QFontMetrics metrics(toolopt->font);
|
||||
|
||||
int space = metrics.horizontalAdvance(QLatin1Char(' '));
|
||||
textRect = QStyle::visualRect(opt->direction, rect, textRect);
|
||||
|
||||
if(toolopt->toolButtonStyle == Qt::ToolButtonTextOnly)
|
||||
{
|
||||
textRect.adjust(3 + space, 0, -3 - space, 0);
|
||||
}
|
||||
|
||||
const QString elidedText = metrics.elidedText(toolopt->text, Qt::ElideRight, textRect.width());
|
||||
|
||||
// if we elided, align left now
|
||||
if(elidedText.length() < toolopt->text.length())
|
||||
{
|
||||
textFlags &= ~Qt::AlignCenter;
|
||||
textFlags |= Qt::AlignLeft | Qt::AlignVCenter;
|
||||
}
|
||||
|
||||
proxy()->drawItemText(p, textRect, textFlags, toolopt->palette,
|
||||
toolopt->state & State_Enabled, elidedText, QPalette::ButtonText);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user