From 6e295f7172597f934be4bc9486ae6a5f9068d197 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 5 Apr 2023 17:09:54 +0300 Subject: [PATCH] Fix list of dimension popup list. Make sure it will always has enough space for values. --- ChangeLog.txt | 1 + src/app/tape/tmainwindow.cpp | 15 +++++++++++++++ src/app/valentina/mainwindow.cpp | 15 +++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 2c214ecf4..415a203b3 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -20,6 +20,7 @@ - Fix float-point accuracy issue in multisize measurements dimensions. - Fix compatibility with Richpeace DXF-AAMA/ASTM R12. - Fix seam allowance. Loose requirements to case with prong. +- Fix list of dimension popup list. Make sure it will always has enough space for values. # Valentina 0.7.52 September 12, 2022 - Fix crash when default locale is ru. diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index cc57ae626..dae8c1d40 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -2905,6 +2905,21 @@ void TMainWindow::InitDimensionGradation(int index, const MeasurementDimension_p InitDimensionYWZItems(bases, labels, control, unit, dimension->IsBodyMeasurement(), fc); } + // Calculate the width of the largest item using QFontMetrics + QFontMetrics fontMetrics(control->font()); + int maxWidth = 0; + for (int i = 0; i < control->count(); ++i) + { + int itemWidth = TextWidth(fontMetrics, control->itemText(i)); + if (itemWidth > maxWidth) + { + maxWidth = itemWidth; + } + } + + // Set the minimum width of the view to the largest item width + control->view()->setMinimumWidth(maxWidth); + // after initialization the current index is 0. The signal for changing the index will not be triggered if not make // it invalid first control->setCurrentIndex(-1); diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 0e37867ea..e149a10b9 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -4918,6 +4918,21 @@ void MainWindow::InitDimensionGradation(int index, const MeasurementDimension_p InitDimensionYWZGradation(bases, labels, control, dimension->IsBodyMeasurement()); } + // Calculate the width of the largest item using QFontMetrics + QFontMetrics fontMetrics(control->font()); + int maxWidth = 0; + for (int i = 0; i < control->count(); ++i) + { + int itemWidth = TextWidth(fontMetrics, control->itemText(i)); + if (itemWidth > maxWidth) + { + maxWidth = itemWidth; + } + } + + // Set the minimum width of the view to the largest item width + control->view()->setMinimumWidth(maxWidth); + // after initialization the current index is 0. The signal for changing the index will not be triggered if not make // it invalid first control->setCurrentIndex(-1);