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()函数时,问题已解决,但我需要使用该函数来保存图形。有想法吗?

解决方法

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...