我有几个标签(在单击按钮时动态生成,并且可以从配置文件读取的数字有所不同)并添加到 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));
我的理想情况是,当我选择任何标签时,它将保持其在运行时根据配置设置加载时获得的大小。但是当我开始流式传输时,下面的事件发生了。
突然选择的标签(参见“LABEL 11”位置的黑色图片标签)开始扩展到很多甚至导致应用程序扩展。理想情况下,我希望上面的事件如下(假设白色背景是视频帧)没有任何扩展。
我的问题是如何在标签上设置像素图时阻止这种不希望的标签扩展?
最佳答案
将标签的大小策略设置为忽略:
placeHolder->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
关于c++ - 如何停止 QGridLayout 元素的扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49125537/