c++ - 如何停止 QGridLayout 元素的扩展

标签 c++ qt user-interface qt5

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

enter image description here

这些标签是按如下方式生成和添加的

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));

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

enter image description here

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

enter image description here

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

最佳答案

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

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

关于c++ - 如何停止 QGridLayout 元素的扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49125537/

相关文章:

c++ - QML 和 C++ 图像互操作性

linux - Qt交叉编译Raspi3 - fatal error : unistd. h: No such file or directory

java - 如何在java中覆盖文本文件?

c++ - 尝试在多集中插入元素时发生C++ 11编译错误

C++ 在不使用 C 字符串库函数的情况下替换数组中的字符

c++ - 使用线程运行服务器时的确切操作顺序

qt - 有没有办法访问 QWidget 后备存储中的图像?

c++ - malloc 只分配 4 位?

user-interface - 解释避免水平滚动的必要性

java - 如何在java中关闭包含框架的单个类