【问题标题】:How to stop expansion of QGridLayout element如何停止 QGridLayout 元素的扩展
【发布时间】:2018-03-06 07:32:07
【问题描述】:

我有几个标签(在按钮单击时动态生成,并且从配置文件中读取的数字可能会有所不同)并添加到 QGridLayout。加载后如下所示...

这些标签的生成和添加如下

QGridLayout * layout = new QGridLayout(ui->pageInputWindow);
layout->setSpacing(5);
layout->setMargin(0);
ui->pageInputWindow->setLayout(layout);
// for question purpose I take number of row and col to 3
// but in actual they will be read from configuration file
for(int row = 0; row < 3; row ++)
{
     for(int col = 0; col < 3; col++)
     {
          QLabel * placeHolder = new QLabel(ui->pageInputWindow);
          placeHolder->setText("LABEL "+QString::number(10*(row+1) + col + 1));
          layout->addWidget(placeHolder, row, col);
     }
}

这些标签放置在此处,用于通过在选中时设置捕获的视频帧的像素图来呈现视频流。我将 pix 设置为 ....

// I am getting img object from other class, below code is just a snap of it.
// You can assume img as valid QImage objcet
QImage img 
selectedLabel->setPixmap(QPixmap::fromImage(img).scaled(selectedLabel->size(),Qt::KeepAspectRatio, Qt::FastTransformation));

我的理想情况是,当我选择任何标签时,它将保持其在运行时根据配置设置加载时获得的大小。但是当我开始流式传输时,发生了以下事件。

突然选择的标签(请参见“标签 11”位置的黑色图片标签)开始扩展很多,甚至导致应用程序扩展。理想情况下,我希望上面的事件如下(假设白色背景是视频帧)没有任何扩展。

我的问题是如何在标签上设置像素图时阻止这种不受欢迎的扩展?

【问题讨论】:

    标签: c++ qt user-interface qt5


    【解决方案1】:

    将标签的大小政策设置为忽略:

    placeHolder->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    

    【讨论】:

      猜你喜欢
      • 2020-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-26
      • 1970-01-01
      • 1970-01-01
      • 2019-05-21
      • 1970-01-01
      相关资源
      最近更新 更多