from PySide6.QtWidgets import QWidget from component.widget_channel.ui_widget_channel import Ui_Widget from PySide6.QtWidgets import (QWidget, QDialog, QVBoxLayout, QComboBox, QPushButton, QLabel, QTableWidgetItem, QAbstractScrollArea, QHBoxLayout, QStyledItemDelegate, QCheckBox) from PySide6.QtCore import Qt, Signal, QEvent from PySide6.QtGui import QPainter, QColor, QPen, QBrush, QPainterPath class Widget_Channel(QWidget): channel_btn_clicked = Signal(int) # (channel_index) solo_btn_clicked = Signal(int) # (channel_index) checkbox_clicked = Signal(int) # (channel_index) def __init__(self): super().__init__() # 初始化UI # self.ui = Ui_Widget_Channel() self.ui = Ui_Widget() self.ui.setupUi(self) self.channel_counts = 24 # 设置连接 # self.setup_connections() self.visible_channels = 24 # 默认显示24个通道 self.update_channel_visibility() def set_visible_channels(self, count: int): """设置可见通道数量""" self.visible_channels = max(1, min(24, count)) # 确保数量在1-24之间 self.channel_counts = count self.update_channel_visibility() def update_channel_visibility(self): """更新通道可见性""" # 获取所有通道的GroupBox channel_groups = [ self.ui.groupBox_CH1, self.ui.groupBox_CH2, self.ui.groupBox_CH3, self.ui.groupBox_CH4, self.ui.groupBox_CH5, self.ui.groupBox_CH6, self.ui.groupBox_CH7, self.ui.groupBox_CH8, self.ui.groupBox_CH9, self.ui.groupBox_CH10, self.ui.groupBox_CH11, self.ui.groupBox_CH12, self.ui.groupBox_CH13, self.ui.groupBox_CH14, self.ui.groupBox_CH15, self.ui.groupBox_CH16, self.ui.groupBox_CH17, self.ui.groupBox_CH18, self.ui.groupBox_CH19, self.ui.groupBox_CH20, self.ui.groupBox_CH21, self.ui.groupBox_CH22, self.ui.groupBox_CH23, self.ui.groupBox_CH24 ] # 设置通道可见性 for i, group in enumerate(channel_groups): group.setVisible(i < self.visible_channels) # 调整布局 self.adjustSize() # def setup_connections(self): # Connect channel buttons using a loop # for i in range(self.channel_counts): # Connect Channel buttons # channel_btn = getattr(self.ui, f'pushButton_Channel_CH{i+1}') # if channel_btn: # channel_btn.clicked.connect(lambda checked, index=i: self.channel_btn_clicked.emit(index)) # for i in range(24): # 假设有24个通道 # channel_btn = getattr(self.ui, f'pushButton_Channel_CH{i+1}') # solo_btn = getattr(self.ui, f'pushButton_SOLO_CH{i+1}') # checkbox = getattr(self.ui, f'checkBox_CH{i+1}') # if channel_btn and solo_btn and checkbox: # # 连接信号 # channel_btn.clicked.connect(lambda checked, ch=i+1: self.on_channel_button_clicked(ch)) # solo_btn.clicked.connect(lambda checked, ch=i+1: self.on_solo_button_clicked(ch)) # checkbox.stateChanged.connect(lambda state, ch=i+1: self.on_checkbox_state_changed(ch, state)) # if channel_btn: # # 连接信号 # channel_btn.clicked.connect(lambda checked, ch=i+1: self.on_channel_button_clicked(ch)) # def setup_connections(self): # """设置信号连接""" # # 遍历通道按钮 # for i in range(24): # 假设有24个通道 # channel_btn = getattr(self.ui, f'pushButton_Channel_CH{i+1}') # # solo_btn = getattr(self.ui, f'pushButton_SOLO_CH{i+1}') # # checkbox = getattr(self.ui, f'checkBox_CH{i+1}') # # if channel_btn and solo_btn and checkbox: # # # 连接信号 # # channel_btn.clicked.connect(lambda checked, ch=i+1: self.on_channel_button_clicked(ch)) # # solo_btn.clicked.connect(lambda checked, ch=i+1: self.on_solo_button_clicked(ch)) # # checkbox.stateChanged.connect(lambda state, ch=i+1: self.on_checkbox_state_changed(ch, state)) # if channel_btn: # # 连接信号 # channel_btn.clicked.connect(lambda checked, ch=i+1: self.on_channel_button_clicked(ch)) # def on_channel_button_clicked(self, channel): # """处理通道按钮点击""" # print(f"Channel {channel} button clicked") def on_solo_button_clicked(self, channel): """处理Solo按钮点击""" print(f"Solo {channel} button clicked") def on_checkbox_state_changed(self, channel, state): """处理复选框状态改变""" print(f"Channel {channel} checkbox state changed to {state}") if __name__ == '__main__': import sys from PySide6.QtWidgets import QApplication app = QApplication(sys.argv) # Create and show the widget widget = Widget_Channel() widget.setup_connections() widget.show() widget.channel_btn_clicked.connect(lambda index: print(f"Channel button {index} clicked")) widget.solo_btn_clicked.connect(lambda index: print(f"Solo button {index} clicked")) widget.checkbox_clicked.connect(lambda index: print(f"Checkbox {index} clicked")) # Start the event loop sys.exit(app.exec())