<knowledge>
  ## Qt样式表(QSS)深度优化技术
  
  ### QSS选择器高级应用
  ```css
  /* 类型选择器 - 选择特定控件类型 */
  QPushButton { background-color: #3498db; }
  
  /* ID选择器 - 选择特定objectName的控件 */
  #loginButton { background-color: #e74c3c; }
  
  /* 类选择器 - 选择特定property的控件 */
  QPushButton[class="primary"] { background-color: #2ecc71; }
  
  /* 状态选择器 - 根据控件状态应用样式 */
  QPushButton:hover { background-color: #2980b9; }
  QPushButton:pressed { background-color: #21618c; }
  QPushButton:disabled { background-color: #bdc3c7; }
  
  /* 子控件选择器 - 选择复合控件的子部分 */
  QComboBox::drop-down { border: none; }
  QScrollBar::handle:vertical { background: #3498db; }
  
  /* 伪状态组合 */
  QPushButton:hover:!pressed { border: 2px solid #3498db; }
  ```

  ### 现代化视觉效果实现
  
  #### 渐变背景系统
  ```css
  /* 线性渐变 - 现代扁平化风格 */
  .modern-panel {
      background: qlineargradient(
          spread:pad, x1:0, y1:0, x2:1, y2:1,
          stop:0 rgba(52, 152, 219, 0.1),
          stop:1 rgba(155, 89, 182, 0.1)
      );
  }
  
  /* 径向渐变 - 按钮悬停效果 */
  QPushButton:hover {
      background: qradialgradient(
          cx:0.5, cy:0.5, radius:1,
          stop:0 rgba(52, 152, 219, 0.8),
          stop:1 rgba(52, 152, 219, 0.4)
      );
  }
  
  /* 三色渐变 - 丰富视觉层次 */
  .header-panel {
      background: qlineargradient(
          spread:pad, x1:0, y1:0, x2:1, y2:0,
          stop:0 #1e3c72,
          stop:0.5 #2a5298,
          stop:1 #1e3c72
      );
  }
  ```

  #### 圆角和边框系统
  ```css
  /* 统一的圆角规范 */
  .card-small { border-radius: 4px; }      /* 小卡片 */
  .card-medium { border-radius: 8px; }     /* 中等卡片 */
  .card-large { border-radius: 12px; }     /* 大卡片 */
  .button-round { border-radius: 20px; }   /* 圆形按钮 */
  
  /* 渐变边框效果 */
  .gradient-border {
      border: 2px solid transparent;
      background: linear-gradient(white, white) padding-box,
                 linear-gradient(45deg, #3498db, #e74c3c) border-box;
  }
  
  /* 阴影效果模拟 */
  .shadow-card {
      border: 1px solid rgba(0,0,0,0.1);
      background-color: white;
      /* Qt不直接支持box-shadow，用边框模拟 */
  }
  ```

  #### 专业配色方案
  ```css
  /* 深色主题配色 */
  :root {
      --dark-bg-primary: #1e1e1e;
      --dark-bg-secondary: #2d2d2d;
      --dark-text-primary: #ffffff;
      --dark-text-secondary: #b0b0b0;
      --dark-accent: #007acc;
  }
  
  /* 蓝色系专业配色 - 适合技术应用 */
  .blue-theme {
      --primary: #3498db;
      --primary-dark: #2980b9;
      --primary-light: #5dade2;
      --secondary: #34495e;
      --accent: #e74c3c;
      --success: #2ecc71;
      --warning: #f39c12;
      --danger: #e74c3c;
  }
  
  /* 军事绿主题 - 适合BattlefieldExplorationSystem */
  .military-theme {
      --primary: #2e5d31;
      --primary-dark: #1e3c22;
      --primary-light: #4a7c59;
      --secondary: #2a3f47;
      --accent: #82c2f2;
      --success: #27ae60;
      --warning: #d68910;
      --danger: #cb4335;
  }
  ```

  ## Qt布局管理器优化技巧
  
  ### 高级布局策略
  ```cpp
  // 智能间距管理类
  class SpacingManager {
  public:
      static const int SPACING_TINY = 4;
      static const int SPACING_SMALL = 8;
      static const int SPACING_NORMAL = 12;
      static const int SPACING_MEDIUM = 16;
      static const int SPACING_LARGE = 20;
      static const int SPACING_XLARGE = 24;
      
      static void applyStandardSpacing(QLayout* layout, SpacingLevel level) {
          switch(level) {
              case COMPACT: layout->setSpacing(SPACING_SMALL); break;
              case NORMAL: layout->setSpacing(SPACING_NORMAL); break;
              case COMFORTABLE: layout->setSpacing(SPACING_MEDIUM); break;
          }
      }
  };
  
  // 响应式布局管理器
  class ResponsiveLayout : public QWidget {
  private:
      QHBoxLayout* wideLayout;
      QVBoxLayout* compactLayout;
      
  protected:
      void resizeEvent(QResizeEvent* event) override {
          if (width() < 768) {
              setLayout(compactLayout);
          } else {
              setLayout(wideLayout);
          }
      }
  };
  ```

  ### 控件尺寸策略优化
  ```cpp
  // 智能尺寸管理
  void optimizeWidgetSizePolicy(QWidget* widget, const QString& role) {
      if (role == "primary-content") {
          widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
      } else if (role == "sidebar") {
          widget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
          widget->setFixedWidth(320);
      } else if (role == "toolbar") {
          widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
          widget->setFixedHeight(48);
      }
  }
  
  // 自适应字体大小
  void adaptiveFontSize(QWidget* widget) {
      QFont font = widget->font();
      int baseSize = 12;
      
      // 根据窗口大小调整字体
      if (widget->window()->width() > 1200) {
          font.setPointSize(baseSize + 2);
      } else if (widget->window()->width() < 800) {
          font.setPointSize(baseSize - 1);
      } else {
          font.setPointSize(baseSize);
      }
      
      widget->setFont(font);
  }
  ```

  ## 性能优化与最佳实践
  
  ### QSS性能优化
  ```cpp
  // 样式表缓存和复用
  class StyleSheetManager {
  private:
      static QHash<QString, QString> styleCache;
      
  public:
      static QString getOptimizedStyle(const QString& component) {
          if (!styleCache.contains(component)) {
              styleCache[component] = loadAndOptimizeStyle(component);
          }
          return styleCache[component];
      }
      
      // 样式表最小化 - 移除注释和多余空格
      static QString minifyStyleSheet(const QString& css) {
          QString minified = css;
          minified.remove(QRegExp("/\\*.*\\*/"));  // 移除注释
          minified.replace(QRegExp("\\s+"), " ");   // 压缩空格
          return minified.trimmed();
      }
  };
  
  // 避免频繁样式更新
  class StyleUpdateManager {
  private:
      QTimer* updateTimer;
      QSet<QWidget*> pendingUpdates;
      
  public:
      void scheduleStyleUpdate(QWidget* widget) {
          pendingUpdates.insert(widget);
          if (!updateTimer->isActive()) {
              updateTimer->start(16); // 60fps update rate
          }
      }
      
  private slots:
      void processPendingUpdates() {
          for (QWidget* widget : pendingUpdates) {
              widget->style()->polish(widget);
          }
          pendingUpdates.clear();
      }
  };
  ```

  ### 内存优化策略
  ```cpp
  // 智能资源管理
  class ResourceManager {
  public:
      // 延迟加载图片资源
      static QPixmap getPixmap(const QString& path) {
          static QHash<QString, QPixmap> pixmapCache;
          if (!pixmapCache.contains(path)) {
              pixmapCache[path] = QPixmap(path);
          }
          return pixmapCache[path];
      }
      
      // 自动清理未使用的样式
      static void cleanupUnusedStyles() {
          // 清理逻辑
      }
  };
  
  // 控件生命周期管理
  void optimizeWidgetLifecycle(QWidget* parent) {
      // 使用Qt的父子关系自动管理内存
      connect(parent, &QWidget::destroyed, [=]() {
          // 清理相关资源
      });
  }
  ```

  ## 界面交互优化技术
  
  ### 平滑动画效果
  ```cpp
  // 自定义属性动画
  class SmoothButton : public QPushButton {
  private:
      QGraphicsOpacityEffect* opacityEffect;
      QPropertyAnimation* animation;
      
  public:
      SmoothButton(QWidget* parent = nullptr) : QPushButton(parent) {
          opacityEffect = new QGraphicsOpacityEffect(this);
          setGraphicsEffect(opacityEffect);
          
          animation = new QPropertyAnimation(opacityEffect, "opacity");
          animation->setDuration(200);
      }
      
  protected:
      void enterEvent(QEvent* event) override {
          animation->setStartValue(1.0);
          animation->setEndValue(0.8);
          animation->start();
          QPushButton::enterEvent(event);
      }
      
      void leaveEvent(QEvent* event) override {
          animation->setStartValue(0.8);
          animation->setEndValue(1.0);
          animation->start();
          QPushButton::leaveEvent(event);
      }
  };
  
  // 页面切换动画
  class PageTransition {
  public:
      static void slideTransition(QWidget* from, QWidget* to, int duration = 300) {
          QPropertyAnimation* fromAnim = new QPropertyAnimation(from, "pos");
          QPropertyAnimation* toAnim = new QPropertyAnimation(to, "pos");
          
          QParallelAnimationGroup* group = new QParallelAnimationGroup;
          group->addAnimation(fromAnim);
          group->addAnimation(toAnim);
          
          fromAnim->setStartValue(from->pos());
          fromAnim->setEndValue(QPoint(-from->width(), from->y()));
          
          toAnim->setStartValue(QPoint(to->width(), to->y()));
          toAnim->setEndValue(QPoint(0, to->y()));
          
          group->setDuration(duration);
          group->start(QAbstractAnimation::DeleteWhenStopped);
      }
  };
  ```

  ### 用户反馈优化
  ```cpp
  // 智能状态反馈
  class StatusFeedback {
  public:
      static void showLoadingState(QWidget* widget) {
          widget->setCursor(Qt::WaitCursor);
          widget->setEnabled(false);
          
          // 添加加载动画
          QMovie* movie = new QMovie(":/icons/loading.gif");
          QLabel* loadingLabel = new QLabel(widget);
          loadingLabel->setMovie(movie);
          movie->start();
      }
      
      static void showSuccessState(QWidget* widget) {
          widget->setCursor(Qt::ArrowCursor);
          widget->setEnabled(true);
          
          // 短暂的成功提示
          QTimer::singleShot(2000, [widget]() {
              // 恢复正常状态
          });
      }
  };
  
  // 触觉反馈模拟
  class HapticFeedback {
  public:
      static void lightTap(QWidget* widget) {
          // 通过简短动画模拟触觉反馈
          QPropertyAnimation* anim = new QPropertyAnimation(widget, "pos");
          anim->setDuration(50);
          anim->setStartValue(widget->pos());
          anim->setEndValue(widget->pos() + QPoint(1, 0));
          anim->setDirection(QAbstractAnimation::Forward);
          
          connect(anim, &QPropertyAnimation::finished, [=]() {
              anim->setDirection(QAbstractAnimation::Backward);
              anim->start(QAbstractAnimation::DeleteWhenStopped);
          });
          
          anim->start();
      }
  };
  ```

  ## 调试和测试工具
  
  ### 界面调试工具
  ```cpp
  // 可视化调试工具
  class UIDebugger {
  public:
      static void highlightWidget(QWidget* widget, const QColor& color = Qt::red) {
          QString style = QString(
              "border: 2px solid %1; background-color: %2;"
          ).arg(color.name()).arg(color.name() + "20");
          
          widget->setStyleSheet(widget->styleSheet() + style);
          
          QTimer::singleShot(2000, [widget]() {
              // 移除高亮
          });
      }
      
      static void showLayoutInfo(QWidget* widget) {
          qDebug() << "Widget:" << widget->objectName();
          qDebug() << "Size:" << widget->size();
          qDebug() << "Position:" << widget->pos();
          qDebug() << "Size Policy:" << widget->sizePolicy().horizontalPolicy() 
                   << widget->sizePolicy().verticalPolicy();
      }
  };
  
  // 性能监控
  class PerformanceMonitor {
  private:
      static QElapsedTimer timer;
      
  public:
      static void startTiming(const QString& operation) {
          qDebug() << "Starting:" << operation;
          timer.start();
      }
      
      static void endTiming(const QString& operation) {
          qint64 elapsed = timer.elapsed();
          qDebug() << "Completed:" << operation << "in" << elapsed << "ms";
          
          if (elapsed > 100) {
              qWarning() << "Slow operation detected:" << operation;
          }
      }
  };
  ```

  ## 可访问性和国际化
  
  ### 可访问性优化
  ```cpp
  // 可访问性属性设置
  void setupAccessibility(QWidget* widget, const QString& role) {
      widget->setAccessibleName(widget->objectName());
      widget->setAccessibleDescription("功能描述");
      
      if (role == "button") {
          widget->setFocusPolicy(Qt::TabFocus);
      } else if (role == "input") {
          widget->setFocusPolicy(Qt::StrongFocus);
      }
  }
  
  // 键盘导航优化
  void setupKeyboardNavigation(QWidget* container) {
      QList<QWidget*> widgets = container->findChildren<QWidget*>();
      for (int i = 0; i < widgets.size() - 1; ++i) {
          QWidget::setTabOrder(widgets[i], widgets[i + 1]);
      }
  }
  ```

  ### 响应式字体和国际化
  ```cpp
  // 多语言字体适配
  class FontManager {
  public:
      static QFont getOptimalFont(const QString& language) {
          QFont font;
          
          if (language == "zh_CN") {
              font.setFamily("Microsoft YaHei, SimHei");
              font.setPointSize(10);
          } else if (language == "en_US") {
              font.setFamily("Segoe UI, Arial");
              font.setPointSize(9);
          }
          
          return font;
      }
      
      static void adjustFontForContent(QWidget* widget, const QString& text) {
          // 根据文本长度调整字体大小
          QFont font = widget->font();
          if (text.length() > 20) {
              font.setPointSize(font.pointSize() - 1);
          }
          widget->setFont(font);
      }
  };
  ```
</knowledge>