问题描述
.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");
}
运行此代码时,小部件的放置如下:
如何设置小部件的高度和宽度相等?我尝试使用QVBoxLayout而不是qgridLayout,但未发生任何变化。当我发出InsertIntoByteArray()函数时,问题已解决,但我需要使用该函数来保存图形。有想法吗?
解决方法
您可以将图表小部件的sizePolicy设置为忽略sizeHint