From 13c4910630ba6633604bad43f2b37d48bee8d5e7 Mon Sep 17 00:00:00 2001 From: jupfi Date: Thu, 13 Jul 2023 15:57:19 +0200 Subject: [PATCH] Added settings in a grid to preserve space. --- .../base_spectrometer_view.py | 23 ++++++++++++++----- .../base_spectrometer_widget.py | 9 +++++--- .../resources/base_spectrometer_widget.ui | 8 +++++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/nqrduck_spectrometer/base_spectrometer_view.py b/src/nqrduck_spectrometer/base_spectrometer_view.py index 602bec7..c51d56c 100644 --- a/src/nqrduck_spectrometer/base_spectrometer_view.py +++ b/src/nqrduck_spectrometer/base_spectrometer_view.py @@ -1,5 +1,6 @@ import logging -from PyQt6.QtWidgets import QWidget, QLabel, QLineEdit, QHBoxLayout, QSizePolicy, QSpacerItem +from PyQt6.QtWidgets import QWidget, QLabel, QLineEdit, QHBoxLayout, QSizePolicy, QSpacerItem, QVBoxLayout +from PyQt6.QtCore import Qt from nqrduck.module.module_view import ModuleView logger = logging.getLogger(__name__) @@ -21,17 +22,24 @@ class BaseSpectrometerView(ModuleView): self.widget = widget self._ui_form.setupUi(self) + grid = self._ui_form.gridLayout + self._ui_form.verticalLayout.removeItem(self._ui_form.gridLayout) # Add name of the spectrometer to the view label = QLabel("%s Settings:" % self.module.model.toolbar_name) label.setStyleSheet("font-weight: bold;") self._ui_form.verticalLayout.setSpacing(5) self._ui_form.verticalLayout.addWidget(label) + self._ui_form.verticalLayout.addLayout(grid) - for category in self.module.model.settings.keys(): + for category_count, category in enumerate(self.module.model.settings.keys()): logger.debug("Adding settings for category: %s", category) + category_layout = QVBoxLayout() category_label = QLabel("%s:" % category) - category_label.setStyleSheet("font-weight: underline;") - self._ui_form.verticalLayout.addWidget(category_label) + category_label.setStyleSheet("font-weight: bold;") + row = category_count // 2 + column = category_count % 2 + + category_layout.addWidget(category_label) for setting in self.module.model.settings[category]: logger.debug("Adding setting to settings view: %s", setting.name) @@ -52,9 +60,12 @@ class BaseSpectrometerView(ModuleView): layout.addWidget(line_edit) layout.addStretch(1) # Add the layout to the vertical layout of the widget - self._ui_form.verticalLayout.addLayout(layout) + category_layout.addLayout(layout) + + category_layout.addStretch(1) + self._ui_form.gridLayout.addLayout(category_layout, row, column) + # Push all the settings to the top of the widget self._ui_form.verticalLayout.addStretch(1) - \ No newline at end of file diff --git a/src/nqrduck_spectrometer/base_spectrometer_widget.py b/src/nqrduck_spectrometer/base_spectrometer_widget.py index fbec072..37465dc 100644 --- a/src/nqrduck_spectrometer/base_spectrometer_widget.py +++ b/src/nqrduck_spectrometer/base_spectrometer_widget.py @@ -13,11 +13,14 @@ class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(800, 647) - self.horizontalLayout = QtWidgets.QHBoxLayout(Form) - self.horizontalLayout.setObjectName("horizontalLayout") + self.verticalLayout_2 = QtWidgets.QVBoxLayout(Form) + self.verticalLayout_2.setObjectName("verticalLayout_2") self.verticalLayout = QtWidgets.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") - self.horizontalLayout.addLayout(self.verticalLayout) + self.gridLayout = QtWidgets.QGridLayout() + self.gridLayout.setObjectName("gridLayout") + self.verticalLayout.addLayout(self.gridLayout) + self.verticalLayout_2.addLayout(self.verticalLayout) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) diff --git a/src/nqrduck_spectrometer/resources/base_spectrometer_widget.ui b/src/nqrduck_spectrometer/resources/base_spectrometer_widget.ui index ea3e7a3..15f119d 100644 --- a/src/nqrduck_spectrometer/resources/base_spectrometer_widget.ui +++ b/src/nqrduck_spectrometer/resources/base_spectrometer_widget.ui @@ -13,9 +13,13 @@ Form - + - + + + + +