【问题标题】:QGridLayout Widgets Set Equal SizeQGridLayout 小部件设置相等大小
【发布时间】:2020-12-28 14:04:33
【问题描述】:

.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() 函数问题已修复但我需要使用该函数来保存图形。有什么想法吗?

【问题讨论】:

    标签: c++ qt qlayout qgridlayout


    【解决方案1】:

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

    【讨论】:

    • 那行得通。 this->chrtViewArr[i]->setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored);
    猜你喜欢
    • 2017-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多