Improved scaling of name LineEdit.

This commit is contained in:
jupfi 2024-05-16 15:23:57 +02:00
parent 0cd3f915f8
commit 136e9ab90b

View file

@ -302,13 +302,13 @@ class MeasurementView(ModuleView):
edit_button = QPushButton() edit_button = QPushButton()
edit_button.setIcon(Logos.Pen12x12()) edit_button.setIcon(Logos.Pen12x12())
edit_button.setFixedWidth(edit_button.iconSize().width()) edit_button.setFixedWidth(edit_button.iconSize().width())
edit_button.clicked.connect( edit_button.clicked.connect(lambda: self.show_measurement_edit(measurement))
lambda: self.show_measurement_edit(measurement)
)
name_button = QPushButton() name_button = QPushButton()
name_button.clicked.connect( name_button.clicked.connect(
partial(self.module.controller.change_displayed_measurement, measurement) partial(
self.module.controller.change_displayed_measurement, measurement
)
) )
# Not sure if this is pretty # Not sure if this is pretty
@ -365,8 +365,6 @@ class MeasurementView(ModuleView):
else: else:
logger.debug("Measurement edit canceled.") logger.debug("Measurement edit canceled.")
class MeasurementDialog(QDialog): class MeasurementDialog(QDialog):
"""This Dialog is shown when the measurement is started and therefore blocks the main window. """This Dialog is shown when the measurement is started and therefore blocks the main window.
@ -414,11 +412,13 @@ class MeasurementView(ModuleView):
It allows the user to edit the measurement parameters (e.g. name, ...) It allows the user to edit the measurement parameters (e.g. name, ...)
""" """
def __init__(self, measurement, parent = None) -> None: def __init__(self, measurement, parent=None) -> None:
"""Initialize the dialog.""" """Initialize the dialog."""
super().__init__(parent) super().__init__(parent)
self.setParent(parent) self.setParent(parent)
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
logger.debug("Edit measurement dialog started.") logger.debug("Edit measurement dialog started.")
self.measurement = measurement self.measurement = measurement
@ -427,12 +427,13 @@ class MeasurementView(ModuleView):
self.layout = QVBoxLayout(self) self.layout = QVBoxLayout(self)
self.setLayout(self.layout) self.setLayout(self.layout)
self.name_layout = QHBoxLayout() self.name_layout = QHBoxLayout()
self.name_label = QLabel("Name:") self.name_label = QLabel("Name:")
self.name_edit = QLineEdit() self.name_edit = QLineEdit(measurement.name)
self.name_edit.setText(measurement.name) font_metrics = self.name_edit.fontMetrics()
self.name_edit.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) self.name_edit.setFixedWidth(
font_metrics.horizontalAdvance(self.name_edit.text()) + 10
)
self.name_edit.adjustSize() self.name_edit.adjustSize()
self.name_layout.addWidget(self.name_label) self.name_layout.addWidget(self.name_label)