Replace obsoleted QFontMetrics::width()

Qt 5.13 marked QFontMetrics::width() obsolete.
This commit is contained in:
Chocobo1
2019-07-01 14:34:02 +08:00
parent c0557c296a
commit 4eff268095
3 changed files with 30 additions and 0 deletions

View File

@@ -80,17 +80,29 @@ void AutoExpandableDialog::showEvent(QShowEvent *e)
// Show dialog and resize textbox to fit the text
// NOTE: For unknown reason QFontMetrics gets more accurate when called from showEvent.
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int wd = m_ui->textEdit->fontMetrics().horizontalAdvance(m_ui->textEdit->text()) + 4;
#else
int wd = m_ui->textEdit->fontMetrics().width(m_ui->textEdit->text()) + 4;
#endif
if (!windowTitle().isEmpty()) {
// not really the font metrics in window title, so we enlarge it a bit,
// including the small icon and close button width
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int w = fontMetrics().horizontalAdvance(windowTitle()) * 1.8;
#else
int w = fontMetrics().width(windowTitle()) * 1.8;
#endif
wd = std::max(wd, w);
}
if (!m_ui->textLabel->text().isEmpty()) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
int w = m_ui->textLabel->fontMetrics().horizontalAdvance(m_ui->textLabel->text());
#else
int w = m_ui->textLabel->fontMetrics().width(m_ui->textLabel->text());
#endif
wd = std::max(wd, w);
}