diff options
-rw-r--r-- | desktop-widgets/divelistview.cpp | 10 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 4 | ||||
-rw-r--r-- | desktop-widgets/tableview.cpp | 7 |
3 files changed, 18 insertions, 3 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index dd74bd46b..a34d78e5c 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -90,11 +90,17 @@ void DiveListView::resetModel() void DiveListView::calculateInitialColumnWidth(int col) { const QFontMetrics metrics(defaultModelFont()); + QString header_txt = MultiFilterSortModel::instance()->headerData(col, Qt::Horizontal, Qt::DisplayRole).toString(); + +#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) int em = metrics.width('m'); int zw = metrics.width('0'); - - QString header_txt = MultiFilterSortModel::instance()->headerData(col, Qt::Horizontal, Qt::DisplayRole).toString(); int width = metrics.width(header_txt); +#else // QT 5.11 or newer + int em = metrics.horizontalAdvance('m'); + int zw = metrics.horizontalAdvance('0'); + int width = metrics.horizontalAdvance(header_txt); +#endif int sw = 0; switch (col) { case DiveTripModelBase::NR: diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 3a92656ad..ddb174984 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -97,7 +97,11 @@ extern "C" int updateProgress(const char *text) if (progressDialog) { // apparently we don't always get enough space to show the full label // so let's manually make enough space (but don't shrink the existing size) +#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) int width = QFontMetrics(qApp->font()).width(text) + 100; +#else // QT 5.11 or newer + int width = QFontMetrics(qApp->font()).horizontalAdvance(text) + 100; +#endif if (width > progressDialog->width()) progressDialog->resize(width + 20, progressDialog->height()); progressDialog->setLabelText(text); diff --git a/desktop-widgets/tableview.cpp b/desktop-widgets/tableview.cpp index 13f7a9d03..19aaf602b 100644 --- a/desktop-widgets/tableview.cpp +++ b/desktop-widgets/tableview.cpp @@ -139,7 +139,12 @@ int TableView::defaultColumnWidth(int col) { int width; QString text = ui.tableView->model()->headerData(col, Qt::Horizontal).toString(); - width = text.isEmpty() ? metrics.rm_col_width : defaultModelFontMetrics().width(text) + 4; // add small margin +#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0) + int textSpace = defaultModelFontMetrics().width(text) + 4; +#else // QT 5.11 or newer + int textSpace = defaultModelFontMetrics().horizontalAdvance(text) + 4; +#endif + width = text.isEmpty() ? metrics.rm_col_width : textSpace + 4; // add small margin #if defined(Q_OS_MAC) width += 10; // Mac needs more margin #endif |