Kaynağa Gözat

修复布局

zhuizhu 7 ay önce
ebeveyn
işleme
bf9c735507

+ 6 - 5
MainPanel.cpp

@@ -120,11 +120,11 @@ void MainPanel::initLayoutComponents()
     // 为playerContainer设置初始布局
     QVBoxLayout *playerLayout = new QVBoxLayout(playerContainer);
     playerLayout->setContentsMargins(0, 0, 0, 0);
+    playerLayout->setSpacing(0);
 }
 
 void MainPanel::initFunctionButtons()
 {
-    
     buttonGroup = new PopoverButtonGroup(Qt::Horizontal, playerContainer);
 
     // 添加功能按钮
@@ -218,9 +218,10 @@ void MainPanel::initFunctionButtons()
     if (!playerLayout) {
         playerLayout = new QVBoxLayout(playerContainer);
         playerLayout->setContentsMargins(0, 0, 0, 0);
+        playerLayout->setSpacing(0);
     }
-    playerLayout->addStretch(1);  // 添加弹性空间,将buttonGroup推到底部
-    playerLayout->addWidget(buttonGroup, 0);  // 添加buttonGroup到底部,不拉伸
+    // 移除addStretch,让buttonGroup紧贴播放器组件,消除空白区域
+    playerLayout->addWidget(buttonGroup, 0);  // 添加buttonGroup,不拉伸
     buttonGroup->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);  // 使用固定大小策略
 }
 
@@ -316,12 +317,12 @@ void MainPanel::setPlayerWidget(QWidget *newPlayer)
 
     // 将新播放器添加到容器布局
     if (auto layout = qobject_cast<QVBoxLayout*>(playerContainer->layout())) {
-        layout->insertWidget(0, playerWidget, 1);
+        layout->insertWidget(0, playerWidget, 1);  // 使用拉伸因子1,让播放器组件充分利用空间
     } else {
         auto layout2 = new QVBoxLayout(playerContainer);
         layout2->setContentsMargins(0, 0, 0, 0);
         layout2->setSpacing(0);
-        layout2->addWidget(playerWidget, 1);
+        layout2->addWidget(playerWidget, 1);  // 使用拉伸因子1,让播放器组件充分利用空间
     }
 
     // 更新推流按钮可见性

+ 3 - 0
libs/AVPlayer/avopenglwidget.cpp

@@ -36,6 +36,9 @@ AVOpenGLWidget::AVOpenGLWidget(QWidget* parent)
     , m_tipTexture(0)
     , m_tipAngle(0.0f)
 {
+    // 设置OpenGL组件的尺寸策略,确保有足够的显示空间
+    setMinimumSize(320, 240);
+    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     // setAttribute(Qt::WA_NoSystemBackground, true);
     // setAttribute(Qt::WA_OpaquePaintEvent, true);
     // setAutoFillBackground(false);

+ 30 - 4
libs/AVPlayer/avplayerwidget.cpp

@@ -12,6 +12,9 @@ AVPlayerWidget::AVPlayerWidget(QWidget *parent)
     , m_isPlaying(false)
     , m_isPaused(false)
 {
+    // 设置尺寸策略,确保能够正确填充空间
+    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    
     setupUI();
     connectSignals();
     
@@ -33,26 +36,46 @@ AVPlayerWidget::~AVPlayerWidget()
 void AVPlayerWidget::setupUI()
 {
     m_mainLayout = new QVBoxLayout(this);
+    m_mainLayout->setContentsMargins(5, 5, 5, 5);  // 减少主布局边距
+    m_mainLayout->setSpacing(5);  // 减少组件间距
     
     // 添加OpenGL视频渲染组件
     m_mainLayout->addWidget(m_openglWidget, 1);
     
-    // 创建控制面板
-    m_controlLayout = new QHBoxLayout();
+    // 创建控制面板容器
+    QWidget *controlWidget = new QWidget(this);
+    controlWidget->setFixedHeight(60);  // 设置控制面板固定高度
+    controlWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+    
+    m_controlLayout = new QHBoxLayout(controlWidget);
+    m_controlLayout->setContentsMargins(5, 5, 5, 5);  // 减少控制面板内边距
+    m_controlLayout->setSpacing(5);  // 减少控件间距
     
     // URL输入框
     m_urlEdit = new QLineEdit(this);
     m_urlEdit->setPlaceholderText("输入视频文件路径或URL");
+    m_urlEdit->setFixedHeight(30);  // 固定高度适应控制面板
+    m_urlEdit->setFont(QFont("Arial", 9));
     m_controlLayout->addWidget(m_urlEdit, 2);
     
     // 测试播放按钮
     m_testPlayButton = new QPushButton("测试播放", this);
+    m_testPlayButton->setFixedSize(70, 30);  // 固定尺寸
+    m_testPlayButton->setFont(QFont("Arial", 9, QFont::Bold));
     m_controlLayout->addWidget(m_testPlayButton);
     
     // 播放控制按钮
     m_playButton = new QPushButton("播放", this);
+    m_playButton->setFixedSize(50, 30);  // 固定尺寸
+    m_playButton->setFont(QFont("Arial", 9, QFont::Bold));
+    
     m_pauseButton = new QPushButton("暂停", this);
+    m_pauseButton->setFixedSize(50, 30);  // 固定尺寸
+    m_pauseButton->setFont(QFont("Arial", 9, QFont::Bold));
+    
     m_stopButton = new QPushButton("停止", this);
+    m_stopButton->setFixedSize(50, 30);  // 固定尺寸
+    m_stopButton->setFont(QFont("Arial", 9, QFont::Bold));
     
     m_controlLayout->addWidget(m_playButton);
     m_controlLayout->addWidget(m_pauseButton);
@@ -60,19 +83,22 @@ void AVPlayerWidget::setupUI()
     
     // 音量控制
     QLabel *volumeLabel = new QLabel("音量:", this);
+    volumeLabel->setFont(QFont("Arial", 9));
     m_volumeSlider = new QSlider(Qt::Horizontal, this);
     m_volumeSlider->setRange(0, 100);
     m_volumeSlider->setValue(50);
-    m_volumeSlider->setMaximumWidth(100);
+    m_volumeSlider->setFixedSize(100, 20);  // 固定尺寸
     
     m_controlLayout->addWidget(volumeLabel);
     m_controlLayout->addWidget(m_volumeSlider);
     
     // 时间显示
     m_timeLabel = new QLabel("00:00 / 00:00", this);
+    m_timeLabel->setFont(QFont("Arial", 9));
+    m_timeLabel->setFixedWidth(80);
     m_controlLayout->addWidget(m_timeLabel);
     
-    m_mainLayout->addLayout(m_controlLayout);
+    m_mainLayout->addWidget(controlWidget, 0);  // 拉伸因子为0,不占用额外空间
     
     // 设置初始状态
     m_pauseButton->setEnabled(false);

+ 2 - 2
main.cpp

@@ -118,8 +118,8 @@ zlmediakit/zlmediakit:master
     // RecorderWidget testRecorder;
     // testRecorder.show();
 
-    // AVPlayerWidget avPlayerWidget;
-    // avPlayerWidget.show();
+    AVPlayerWidget avPlayerWidget;
+    avPlayerWidget.show();
 
     int ret = a.exec();
 

+ 19 - 28
widgets/recorderwidget.cpp

@@ -40,6 +40,11 @@ RecorderWidget::RecorderWidget(QWidget *parent)
     s_instance = this;
     // rtmp://106.55.186.74:1935/stream/V1/0198da41-cdb6-78e3-879d-2ea32d58f73f
 
+    // 设置初始大小,与AVPlayerWidget保持一致
+    setMinimumSize(640, 480);
+    resize(800, 600);
+    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+
     // 初始化默认设置
     m_settings.liveUrl = "rtmp://106.55.186.74:1935/stream/V1";
     m_settings.liveName = "0198da41-cdb6-78e3-879d-2ea32d58f73f";
@@ -71,40 +76,26 @@ void RecorderWidget::initUI()
 {
     m_mainLayout = new QVBoxLayout(this);
     m_mainLayout->setContentsMargins(0, 0, 0, 0);
+    m_mainLayout->setSpacing(0);
     
-    // 预览区域已移除
-    // m_previewWidget = new QOpenGLWidget(this);
-    // m_previewWidget->setMinimumSize(640, 480);
-    // m_previewWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
-    
-    // 控制区域
-    QWidget* controlWidget = new QWidget(this);
-    QHBoxLayout* controlLayout = new QHBoxLayout(controlWidget);
-    
-    // 移除设备/编码分组(编码器选择改由 MainPanel 控制)
-    // QGroupBox* deviceGroup = new QGroupBox("设备/编码", this);
-    // QVBoxLayout* deviceLayout = new QVBoxLayout(deviceGroup);
+    // 上部分:空白区域,占据主要空间
+    QWidget* blankWidget = new QWidget(this);
+    blankWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    blankWidget->setStyleSheet("background-color: #2b2b2b; border: 1px solid #555;");
     
-    // // 编码器选择(已移除)
-    // QHBoxLayout* encoderLayout = new QHBoxLayout();
-    // encoderLayout->addWidget(new QLabel("编码器:"));
-    // m_encoderComboBox = new QComboBox(this);
-    // encoderLayout->addWidget(m_encoderComboBox);
-    // deviceLayout->addLayout(encoderLayout);
-    
-    // 右侧操作区已移除,所有控制按钮已迁移到MainPanel
-    controlLayout->addStretch();
+    // 可以在空白区域添加一些提示信息
+    QVBoxLayout* blankLayout = new QVBoxLayout(blankWidget);
+    QLabel* hintLabel = new QLabel("录制预览区域", this);
+    hintLabel->setAlignment(Qt::AlignCenter);
+    hintLabel->setStyleSheet("color: #888; font-size: 14px; border: none;");
+    blankLayout->addWidget(hintLabel);
     
     // 状态栏
     initStatusBar();
     
-    // 添加到主布局(预览区域已移除)
-    // m_mainLayout->addWidget(m_previewWidget, 1);
-    m_mainLayout->addWidget(controlWidget, 0);
-    m_mainLayout->addStretch(1);
-    m_mainLayout->addWidget(m_statusBar, 0);
-    
-    // 连接信号槽已移除,按钮控制已迁移到MainPanel
+    // 添加到主布局:上部分空白区域占据主要空间,下部分状态栏
+    m_mainLayout->addWidget(blankWidget, 1);  // 拉伸因子为1,占据主要空间
+    m_mainLayout->addWidget(m_statusBar, 0);  // 拉伸因子为0,固定高度
 }
 
 void RecorderWidget::initStatusBar()