mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Backport QFontMetrics::width deprecation fix
This commit is contained in:
parent
7922b761f5
commit
472f4f0a9d
@ -243,7 +243,11 @@ void CCItemDelegate::drawCategoryHeader(QPainter * painter, QStyleOptionViewItem
|
||||
|
||||
// draw the centered text
|
||||
QFontMetrics fm(font);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
int w = fm.horizontalAdvance(category);
|
||||
#else
|
||||
int w = fm.width(category);
|
||||
#endif
|
||||
int x = opt.rect.x() + (opt.rect.width() - w) / 2;
|
||||
int y = opt.rect.y() + 3 * fm.ascent() / 2;
|
||||
int left = x;
|
||||
|
@ -480,7 +480,13 @@ PreambleModule::PreambleModule(QWidget * parent)
|
||||
// https://stackoverflow.com/questions/13027091/how-to-override-tab-width-in-qt
|
||||
const int tabStop = 4;
|
||||
QFontMetrics metrics(preambleTE->currentFont());
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
// horizontalAdvance() is available starting in 5.11.0
|
||||
// setTabStopDistance() is available starting in 5.10.0
|
||||
preambleTE->setTabStopDistance(tabStop * metrics.horizontalAdvance(' '));
|
||||
#else
|
||||
preambleTE->setTabStopWidth(tabStop * metrics.width(' '));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
@ -271,7 +271,11 @@ void LayoutItemDelegate::drawCategoryHeader(QPainter * painter, QStyleOptionView
|
||||
|
||||
// draw the centered text
|
||||
QFontMetrics fm(font);
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
int w = fm.horizontalAdvance(category);
|
||||
#else
|
||||
int w = fm.width(category);
|
||||
#endif
|
||||
int x = opt.rect.x() + (opt.rect.width() - w) / 2;
|
||||
int y = opt.rect.y() + fm.ascent();
|
||||
int left = x;
|
||||
|
@ -640,7 +640,11 @@ QString formatToolTip(QString text, int em)
|
||||
text = Qt::convertFromPlainText(text, Qt::WhiteSpaceNormal);
|
||||
// Compute desired width in pixels
|
||||
QFont const font = QToolTip::font();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
int const px_width = em * QFontMetrics(font).horizontalAdvance("M");
|
||||
#else
|
||||
int const px_width = em * QFontMetrics(font).width("M");
|
||||
#endif
|
||||
// Determine the ideal width of the tooltip
|
||||
QTextDocument td("");
|
||||
td.setHtml(text);
|
||||
|
Loading…
Reference in New Issue
Block a user