diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2017-08-02 11:39:01 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2017-12-08 15:06:32 +0000 |
commit | 4d88d79aa507777bce40740b21747f656efc074d (patch) | |
tree | 0b335cac61062eaf281b5a76514f8bd74bbcaaf2 /examples/network/torrent/mainwindow.cpp | |
parent | cd56e843cc53938111879c21570eaf8225719743 (diff) |
Update usage of QFontMetrics::width() to new API
QFontMetrics(F)::width() has been deprecated and is replaced by
horizontalAdvance(). This updates all usage of it in tests and
documentation.
It is worth noting that many or most of the usages of
QFontMetrics::width() probably intended to use boundingRect().width(),
but since it currently works, I have not looked into that, just
replaced the function name mechanically.
Change-Id: Iec382e5bad0b50f37a6cfff841bfb46ed4d4555f
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'examples/network/torrent/mainwindow.cpp')
-rw-r--r-- | examples/network/torrent/mainwindow.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/examples/network/torrent/mainwindow.cpp b/examples/network/torrent/mainwindow.cpp index efdf187174..f80c2c6975 100644 --- a/examples/network/torrent/mainwindow.cpp +++ b/examples/network/torrent/mainwindow.cpp @@ -129,12 +129,12 @@ MainWindow::MainWindow(QWidget *parent) // Set header resize modes and initial section sizes QFontMetrics fm = fontMetrics(); QHeaderView *header = torrentView->header(); - header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent")); - header->resizeSection(1, fm.width(headers.at(1) + " ")); - header->resizeSection(2, fm.width(headers.at(2) + " ")); - header->resizeSection(3, qMax(fm.width(headers.at(3) + " "), fm.width(" 1234.0 KB/s "))); - header->resizeSection(4, qMax(fm.width(headers.at(4) + " "), fm.width(" 1234.0 KB/s "))); - header->resizeSection(5, qMax(fm.width(headers.at(5) + " "), fm.width(tr("Downloading") + " "))); + header->resizeSection(0, fm.horizontalAdvance("typical-name-for-a-torrent.torrent")); + header->resizeSection(1, fm.horizontalAdvance(headers.at(1) + " ")); + header->resizeSection(2, fm.horizontalAdvance(headers.at(2) + " ")); + header->resizeSection(3, qMax(fm.horizontalAdvance(headers.at(3) + " "), fm.horizontalAdvance(" 1234.0 KB/s "))); + header->resizeSection(4, qMax(fm.horizontalAdvance(headers.at(4) + " "), fm.horizontalAdvance(" 1234.0 KB/s "))); + header->resizeSection(5, qMax(fm.horizontalAdvance(headers.at(5) + " "), fm.horizontalAdvance(tr("Downloading") + " "))); // Create common actions QAction *newTorrentAction = new QAction(QIcon(":/icons/bottom.png"), tr("Add &new torrent"), this); @@ -174,14 +174,14 @@ MainWindow::MainWindow(QWidget *parent) bottomBar->addWidget(new QLabel(tr("Max download:"))); bottomBar->addWidget(downloadLimitSlider); bottomBar->addWidget((downloadLimitLabel = new QLabel(tr("0 KB/s")))); - downloadLimitLabel->setFixedSize(QSize(fm.width(tr("99999 KB/s")), fm.lineSpacing())); + downloadLimitLabel->setFixedSize(QSize(fm.horizontalAdvance(tr("99999 KB/s")), fm.lineSpacing())); bottomBar->addSeparator(); uploadLimitSlider = new QSlider(Qt::Horizontal); uploadLimitSlider->setRange(0, 1000); bottomBar->addWidget(new QLabel(tr("Max upload:"))); bottomBar->addWidget(uploadLimitSlider); bottomBar->addWidget((uploadLimitLabel = new QLabel(tr("0 KB/s")))); - uploadLimitLabel->setFixedSize(QSize(fm.width(tr("99999 KB/s")), fm.lineSpacing())); + uploadLimitLabel->setFixedSize(QSize(fm.horizontalAdvance(tr("99999 KB/s")), fm.lineSpacing())); #ifdef Q_OS_OSX setUnifiedTitleAndToolBarOnMac(true); @@ -220,7 +220,7 @@ QSize MainWindow::sizeHint() const // Add up the sizes of all header sections. The last section is // stretched, so its size is relative to the size of the width; // instead of counting it, we count the size of its largest value. - int width = fontMetrics().width(tr("Downloading") + " "); + int width = fontMetrics().horizontalAdvance(tr("Downloading") + " "); for (int i = 0; i < header->count() - 1; ++i) width += header->sectionSize(i); |