Skip to content
Snippets Groups Projects
Select Git revision
  • fc32908da7bcdf2825991f7b17ab15ee33d25216
  • master default protected
  • results
  • GDP_4.4.7
  • GDP_4.2.1
  • GDP_4.2.6
6 results

qt_widgets.py

Blame
  • qt_widgets.py 1.64 KiB
    # utils/qt_widgets.py
    from PyQt6.QtWidgets import (QTextEdit, QGroupBox, QVBoxLayout, 
                               QHBoxLayout, QPushButton)
    
    def create_group_with_text(title, height=100):
        """
        Creates a QGroupBox containing a QTextEdit.
        
        Args:
            title: Group box title
            height: Fixed height for text edit
        Returns:
            tuple: (QGroupBox, QTextEdit)
        """
        group = QGroupBox(title)
        layout = QVBoxLayout(group)
        text_edit = QTextEdit()
        text_edit.setFixedHeight(height)
        text_edit.setReadOnly(True)
        layout.addWidget(text_edit)
        return group, text_edit
    
    def create_button_layout(*buttons):
        """
        Creates a horizontal button layout with optional stretch.
        
        Args:
            buttons: List of tuples (label, callback, position)
                    position can be 'left', 'right', or None for default
        Returns:
            QHBoxLayout with arranged buttons
        """
        layout = QHBoxLayout()
        
        # Add left-aligned buttons
        for label, callback, position in buttons:
            if position == 'left':
                btn = QPushButton(label)
                btn.clicked.connect(callback)
                layout.addWidget(btn)
        
        # Add stretch in the middle
        layout.addStretch()
        
        # Add right-aligned buttons
        for label, callback, position in buttons:
            if position == 'right':
                btn = QPushButton(label)
                btn.clicked.connect(callback)
                layout.addWidget(btn)
        
        return layout
    
    def create_status_group():
        """
        Creates a standard status display group.
        
        Returns:
            tuple: (QGroupBox, QTextEdit)
        """
        return create_group_with_text("Status", 80)