Use QFontMetrics instead of fontMetrics()

This commit is contained in:
Anton Kochkov 2023-02-07 21:28:40 +08:00 committed by Anton Kochkov
parent 3e0bc74e77
commit bbd4961468
4 changed files with 13 additions and 9 deletions

View File

@ -1114,7 +1114,7 @@ void MainWindow::initBackForwardMenu()
connect(button, &QWidget::customContextMenuRequested, button,
[menu, button](const QPoint &pos) { menu->exec(button->mapToGlobal(pos)); });
QFontMetrics metrics(fontMetrics());
QFontMetrics metrics(font());
// Roughly 10-16 lines depending on padding size, no need to calculate more precisely
menu->setMaximumHeight(metrics.lineSpacing() * 20);

View File

@ -48,8 +48,9 @@ void ColorOptionDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
ColorOption currCO = index.data(Qt::UserRole).value<ColorOption>();
QFontMetrics fm = QFontMetrics(painter->font());
int penWidth = painter->pen().width();
int fontHeight = painter->fontMetrics().height();
int fontHeight = fm.height();
QPoint tl = option.rect.topLeft();
QRect optionNameRect;
@ -126,9 +127,9 @@ void ColorOptionDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
painter->setPen(qApp->palette().text().color());
QString name =
painter->fontMetrics().elidedText(optionInfoMap__[currCO.optionName].displayingtext,
Qt::ElideRight, optionNameRect.width());
QFontMetrics fm2 = QFontMetrics(painter->font());
QString name = fm2.elidedText(optionInfoMap__[currCO.optionName].displayingtext,
Qt::ElideRight, optionNameRect.width());
painter->drawText(optionNameRect, name);
QPainterPath roundedOptionRect;
@ -155,7 +156,8 @@ void ColorOptionDelegate::paint(QPainter *painter, const QStyleOptionViewItem &o
painter->setPen(currCO.color);
painter->fillPath(roundedColorRect, currCO.color);
QString desc = painter->fontMetrics().elidedText(
QFontMetrics fm3 = QFontMetrics(painter->font());
QString desc = fm3.elidedText(
currCO.optionName + ": " + optionInfoMap__[currCO.optionName].info, Qt::ElideRight,
descTextRect.width());
painter->setPen(qApp->palette().text().color());
@ -197,7 +199,8 @@ QPixmap ColorOptionDelegate::getPixmapFromSvg(const QString &fileName, const QCo
data.replace(QRegularExpression("#[0-9a-fA-F]{6}"), QString("%1").arg(after.name()));
QSvgRenderer svgRenderer(data.toUtf8());
QPixmap pix(QSize(qApp->fontMetrics().height(), qApp->fontMetrics().height()));
QFontMetrics fm = QFontMetrics(qApp->font());
QPixmap pix(QSize(fm.height(), fm.height()));
pix.fill(Qt::transparent);
QPainter pixPainter(&pix);

View File

@ -211,7 +211,7 @@ QString DisassemblyWidget::getWidgetType()
QFontMetrics DisassemblyWidget::getFontMetrics()
{
return mDisasTextEdit->fontMetrics();
return QFontMetrics(mDisasTextEdit->font());
}
QList<DisassemblyLine> DisassemblyWidget::getLines()

View File

@ -119,8 +119,9 @@ void SimpleTextGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block, b
p.setPen(palette().color(QPalette::WindowText));
// Render node text
QFontMetrics fm = QFontMetrics(p.font());
auto x = block.x + padding / 2;
int y = block.y + padding / 2 + p.fontMetrics().ascent();
int y = block.y + padding / 2 + fm.ascent();
p.drawText(QPoint(x, y), content.text);
}