From 72219ee2ed7848b7932cfa4d2524ebee5361be10 Mon Sep 17 00:00:00 2001 From: PingHsunTsai <47770211+PingHsunTsai@users.noreply.github.com> Date: Thu, 25 Jul 2024 02:49:01 +0200 Subject: [PATCH] tab feature --- src/compas_viewer/components/objectsetting.py | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/compas_viewer/components/objectsetting.py b/src/compas_viewer/components/objectsetting.py index 2a536befb..c2a954cd8 100644 --- a/src/compas_viewer/components/objectsetting.py +++ b/src/compas_viewer/components/objectsetting.py @@ -5,6 +5,7 @@ from PySide6.QtWidgets import QDialog from PySide6.QtWidgets import QPushButton from PySide6.QtWidgets import QScrollArea +from PySide6.QtWidgets import QTabWidget from PySide6.QtWidgets import QVBoxLayout from PySide6.QtWidgets import QWidget @@ -60,15 +61,37 @@ def __init__(self, viewer: "Viewer", items: list[dict]): # Main layout self.main_layout = QVBoxLayout(self) - # Scroll area setup - self.scroll_area = QScrollArea(self) - self.scroll_area.setWidgetResizable(True) - self.scroll_content = QWidget() - self.scroll_layout = QVBoxLayout(self.scroll_content) - self.scroll_layout.setAlignment(Qt.AlignTop) - self.scroll_area.setWidget(self.scroll_content) - - self.main_layout.addWidget(self.scroll_area) + # Tab widget setup + self.tab_widget = QTabWidget(self) + + # Tab 1 setup + self.tab1_content = QWidget() + self.tab1_scroll_area = QScrollArea(self.tab1_content) + self.tab1_scroll_area.setWidgetResizable(True) + self.tab1_scroll_content = QWidget() + self.tab1_scroll_layout = QVBoxLayout(self.tab1_scroll_content) + self.tab1_scroll_layout.setAlignment(Qt.AlignTop) + self.tab1_scroll_area.setWidget(self.tab1_scroll_content) + + tab1_layout = QVBoxLayout(self.tab1_content) + tab1_layout.addWidget(self.tab1_scroll_area) + self.tab_widget.addTab(self.tab1_content, "Tab 1") + + # Tab 2 setup + self.tab2_content = QWidget() + self.tab2_scroll_area = QScrollArea(self.tab2_content) + self.tab2_scroll_area.setWidgetResizable(True) + self.tab2_scroll_content = QWidget() + self.tab2_scroll_layout = QVBoxLayout(self.tab2_scroll_content) + self.tab2_scroll_layout.setAlignment(Qt.AlignTop) + self.tab2_scroll_area.setWidget(self.tab2_scroll_content) + + tab2_layout = QVBoxLayout(self.tab2_content) + tab2_layout.addWidget(self.tab2_scroll_area) + self.tab_widget.addTab(self.tab2_content, "Tab 2") + + # Add tab widget to main layout + self.main_layout.addWidget(self.tab_widget) def clear_layout(self, layout): """Clear all widgets from the layout.""" @@ -84,18 +107,18 @@ def clear_layout(self, layout): def update(self): """Update the layout with the latest object settings.""" - self.clear_layout(self.scroll_layout) + self.clear_layout(self.tab1_scroll_layout) self.setting_layout.generate_layout() if len(self.setting_layout.widgets) != 0: - self.scroll_layout.addLayout(self.setting_layout.layout) + self.tab1_scroll_layout.addLayout(self.setting_layout.layout) for _, widget in self.setting_layout.widgets.items(): if isinstance(widget, DoubleEdit): widget.spinbox.valueChanged.connect(self.obj_update) elif isinstance(widget, TextEdit): widget.text_edit.textChanged.connect(self.obj_update) else: - self.scroll_layout.addWidget(LabelWidget(text="No object Selected", alignment="center")) + self.tab1_scroll_layout.addWidget(LabelWidget(text="No object Selected", alignment="center")) def obj_update(self): """Apply the settings from spin boxes to the selected objects."""