QPushButton: fix drawing pushbutton with a menu
Drawing a QPushButton with a menu results in a clipped label text and a wrong aligned decoration and menu button. The position of the menu button was calculated wrong (spacing has to be subtracted since the start position is the right side). Also the text label alignment was done before it was adjusted for the menu button which results in an unaligned (in constrast to a pushbutton without a menu) label and decoration. Fixes: QTBUG-89619 Change-Id: I872d39ff2d8eb685fe6843e38c7f727868e1ee9a Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Funning <huangyub@uniontech.com> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
427e639275
commit
b002c21087
@ -1359,7 +1359,7 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
|
||||
int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, btn, widget);
|
||||
QRect ir = btn->rect;
|
||||
QStyleOptionButton newBtn = *btn;
|
||||
newBtn.rect = QRect(ir.right() - mbi + 2, ir.height()/2 - mbi/2 + 3, mbi - 6, mbi - 6);
|
||||
newBtn.rect = QRect(ir.right() - mbi - 2, ir.height()/2 - mbi/2 + 3, mbi - 6, mbi - 6);
|
||||
newBtn.rect = visualRect(btn->direction, br, newBtn.rect);
|
||||
proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget);
|
||||
}
|
||||
@ -1372,6 +1372,14 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
|
||||
if (!proxy()->styleHint(SH_UnderlineShortcut, button, widget))
|
||||
tf |= Qt::TextHideMnemonic;
|
||||
|
||||
if (button->features & QStyleOptionButton::HasMenu) {
|
||||
int indicatorSize = proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget);
|
||||
if (button->direction == Qt::LeftToRight)
|
||||
textRect = textRect.adjusted(0, 0, -indicatorSize, 0);
|
||||
else
|
||||
textRect = textRect.adjusted(indicatorSize, 0, 0, 0);
|
||||
}
|
||||
|
||||
if (!button->icon.isNull()) {
|
||||
//Center both icon and text
|
||||
QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
|
||||
@ -1417,13 +1425,6 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
|
||||
textRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
|
||||
proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
|
||||
|
||||
if (button->features & QStyleOptionButton::HasMenu) {
|
||||
int indicatorSize = proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget);
|
||||
if (button->direction == Qt::LeftToRight)
|
||||
textRect = textRect.adjusted(0, 0, -indicatorSize, 0);
|
||||
else
|
||||
textRect = textRect.adjusted(indicatorSize, 0, 0, 0);
|
||||
}
|
||||
proxy()->drawItemText(p, textRect, tf, button->palette, (button->state & State_Enabled),
|
||||
button->text, QPalette::ButtonText);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user