Jai
Jai

Reputation: 1332

How to stop expansion of QGridLayout element

I have couple of labels (dynamically generated on button click and can vary in numbers which read from configuration file) and added to QGridLayout. Upon load which looks like below ...

enter image description here

these labels are generated and added as below

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

These label are placed here for rendering video streaming by setting pixmap of captured video frames when selected. I am setting pix as ....

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

My ideal scenario is when I select any label it will remain with size which it got when loaded according to configuration settings at runtime. But when I start streaming below event happened.

enter image description here

Suddenly selected label ( see black pictured label at 'LABEL 11' position) starts expansding to much even causing application to expand. Idealy I want above event as below ( assume white background is video frame ) without any expansion.

enter image description here

My question is how can I stop this undesirable expansion of labels while setting pix map on them ?

Upvotes: 0

Views: 353

Answers (1)

SteakOverflow
SteakOverflow

Reputation: 2033

Set the labels' size policies to ignored:

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

Upvotes: 1

Related Questions