Widgets QGridLayout com tamanho igual

Sep 10 2020

arquivo .h:

QChartView *chrtViewArr[5];
QGridLayout *graphLayout;
QFrame *graphFrame;

arquivo .cpp:

{
...
this->graphLayout = new QGridLayout(this->graphFrame);

for(int i=0;i<3;i++){
        this->graphLayout->addWidget(this->chrtViewArr[i],i,0);
    }

this->graphFrame->setLayout(this->graphLayout);

for(int i=0;i<machine_count;i++){
        this->InsertIntoByteArray(this->chrtViewArr[i]);
    }
...
widget.show();
}

void GraphDialog::InsertIntoByteArray(QChartView *chartView){
    this->pixmap = chartView->grab();
    QBuffer buffer(&this->byteArray);
    buffer.open(QIODevice::WriteOnly);
    this->pixmap.save(&buffer,"JPG");
}

Quando executo este código, o posicionamento dos widgets é assim:

Como posso definir a altura e a largura do widget iguais? Tentei usar QVBoxLayout em vez de QGridLayout, mas nada mudou. Quando eu comando a função InsertIntoByteArray (), o problema foi corrigido, mas preciso usar essa função para salvar gráficos. Qualquer ideia?

Respostas

1 PatrickParker Sep 10 2020 at 13:28

Você pode definir o sizePolicy dos widgets do gráfico para ignorar o sizeHint