Search code examples
c++qtqlayoutqgridlayout

QGridLayout Widgets Set Equal Size


.h file:

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

.cpp file:

{
...
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");
}

When I run this code the placement of widgets are like this:widget placement

How can I set the widget height and width equal? I tried to use QVBoxLayout istead of QGridLayout but nothing has changed. When I command out InsertIntoByteArray() function problem fixed but I need to use that function to save graphs. Any idea?


Solution

  • You could set the chart widgets' sizePolicy to ignore the sizeHint