""" 模块列表项组件 """ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel from PyQt5.QtCore import Qt class ModuleItemWidget(QWidget): """模块列表项组件""" def __init__(self, module, parent=None): """ 初始化模块列表项 Args: module: 模块对象 parent: 父组件 """ super().__init__(parent) self.module = module self._setup_ui() def _setup_ui(self): """设置UI""" layout = QVBoxLayout(self) layout.setContentsMargins(15, 15, 15, 15) layout.setSpacing(10) # 模块标题 title_label = QLabel(f"{self.module.icon} {self.module.name}") title_label.setStyleSheet(""" font-weight: bold; color: #60a5fa; font-size: 14px; """) layout.addWidget(title_label) # 模块描述 desc_label = QLabel(self.module.description) desc_label.setStyleSheet(""" color: #94a3b8; font-size: 12px; """) desc_label.setWordWrap(True) layout.addWidget(desc_label) # 需求标签 if self.module.requirements: req_layout = QHBoxLayout() req_layout.setSpacing(5) for req_id in self.module.requirements[:3]: # 最多显示3个 req_label = QLabel(req_id) req_label.setStyleSheet(""" background: #3b82f633; color: #3b82f6; border: 1px solid #3b82f6; border-radius: 4px; padding: 2px 6px; font-size: 11px; """) req_layout.addWidget(req_label) req_layout.addStretch() layout.addLayout(req_layout) # 技术栈标签 if self.module.tech_stack: tech_layout = QHBoxLayout() tech_layout.setSpacing(5) for tech in self.module.tech_stack[:3]: # 最多显示3个 tech_label = QLabel(tech) tech_label.setStyleSheet(""" background: rgba(100, 116, 139, 0.3); color: #94a3b8; border-radius: 4px; padding: 2px 6px; font-size: 11px; """) tech_layout.addWidget(tech_label) tech_layout.addStretch() layout.addLayout(tech_layout) # 设置整体样式 self.setStyleSheet(""" QWidget { background: rgba(51, 65, 85, 0.3); border: 1px solid rgba(59, 130, 246, 0.15); border-radius: 8px; } QWidget:hover { background: rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.3); } """)