QGridLayout小部件设置相等的大小

时间:2020-09-10 05:44:58

标签: c++ qt qlayout qgridlayout

.h文件:

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

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

运行此代码时,小部件的放置如下:widget placement

如何设置小部件的高度和宽度相等?我尝试使用QVBoxLayout而不是QGridLayout,但未发生任何变化。当我发出InsertIntoByteArray()函数时,问题已解决,但我需要使用该函数来保存图形。有想法吗?

1 个答案:

答案 0 :(得分:1)

您可以将图表小部件的sizePolicy设置为忽略sizeHint