QHeaderView: respect the font role while calculating the elided text
Amends 4d943846128118e1b9932a17ce6f977a0f4127a5: - The macOS style must now elide the text by it's own since it is no longer done by QHeaderView - Add documentation of QStyleOptionHeader::textElideMode - Remove unused variables from QHeaderView::initStyleOptionForIndex() Task-number: QTBUG-86426 Change-Id: I98fc6771c0cd56d6002390125ffbab1269f6dd39 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
ac1008c16f
commit
6fa1038a85
@ -3520,9 +3520,12 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
|
||||
proxy()->drawItemPixmap(p, pixr, Qt::AlignVCenter, pixmap);
|
||||
textr.translate(pixmap.width() / pixmap.devicePixelRatio() + 2, 0);
|
||||
}
|
||||
QString text = header->text;
|
||||
if (header->textElideMode != Qt::ElideNone)
|
||||
text = header->fontMetrics.elidedText(text, header->textElideMode, textr.width());
|
||||
|
||||
proxy()->drawItemText(p, textr, header->textAlignment | Qt::AlignVCenter, header->palette,
|
||||
header->state & State_Enabled, header->text, QPalette::ButtonText);
|
||||
header->state.testFlag(State_Enabled), text, QPalette::ButtonText);
|
||||
p->restore();
|
||||
}
|
||||
break;
|
||||
|
@ -2936,21 +2936,11 @@ void QHeaderView::initStyleOptionForIndex(QStyleOptionHeader *option, int logica
|
||||
opt.text = d->model->headerData(logicalIndex, d->orientation,
|
||||
Qt::DisplayRole).toString();
|
||||
|
||||
int margin = 2 * style()->pixelMetric(QStyle::PM_HeaderMargin, nullptr, this);
|
||||
|
||||
const Qt::Alignment headerArrowAlignment = static_cast<Qt::Alignment>(style()->styleHint(QStyle::SH_Header_ArrowAlignment, nullptr, this));
|
||||
const bool isHeaderArrowOnTheSide = headerArrowAlignment & Qt::AlignVCenter;
|
||||
if (isSortIndicatorShown() && sortIndicatorSection() == logicalIndex && isHeaderArrowOnTheSide)
|
||||
margin += style()->pixelMetric(QStyle::PM_HeaderMarkSize, nullptr, this);
|
||||
|
||||
const QVariant variant = d->model->headerData(logicalIndex, d->orientation,
|
||||
Qt::DecorationRole);
|
||||
opt.icon = qvariant_cast<QIcon>(variant);
|
||||
if (opt.icon.isNull())
|
||||
opt.icon = qvariant_cast<QPixmap>(variant);
|
||||
if (!opt.icon.isNull()) // see CT_HeaderSection
|
||||
margin += style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this) +
|
||||
style()->pixelMetric(QStyle::PM_HeaderMargin, nullptr, this);
|
||||
|
||||
QVariant var = d->model->headerData(logicalIndex, d->orientation,
|
||||
Qt::FontRole);
|
||||
|
@ -894,6 +894,16 @@ QStyleOptionHeader::QStyleOptionHeader(int version)
|
||||
\sa sortIndicator
|
||||
*/
|
||||
|
||||
/*!
|
||||
\variable QStyleOptionHeader::textElideMode
|
||||
\brief where ellipsis should be added for text that is too long to fit
|
||||
into an item
|
||||
|
||||
The default value is Qt::ElideNone.
|
||||
|
||||
\sa Qt::TextElideMode
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class QStyleOptionButton
|
||||
\brief The QStyleOptionButton class is used to describe the
|
||||
|
Loading…
x
Reference in New Issue
Block a user