具有不同大小单元格的 QGridLayout

mae*_*orn 4 c++ grid qt

我试图设置一个带有四个小部件的 QGridLayout ,如下图所示:目标

然而我现在用 QGridLayout 管理的是:现在的情况

我不明白如何为第 0 列和第 1 列设置不同的行大小。也许 QGridLayout 不是正确的方法,但我不知道有任何其他小部件可以做到这一点。有谁知道如何实现这一目标?

vah*_*cho 5

我会使用垂直和水平布局而不是网格布局。所以你需要两种垂直布局和水平布局:

// Left side
QLabel *lbl1 = new QLabel(this);
QTableWidget *t = new QTableWidget(this);
QVBoxLayout *vl1 = new QVBoxLayout;
vl1->addWidget(lbl1);
vl1->addWidget(t);

// Right side
// QImage is not a widget, so it should be a label with image
QLabel *lbl2 = new QLabel(this);
QCustomPlot *pl = new QCustomPlot(this);
QVBoxLayout *vl2 = new QVBoxLayout;
vl2->addWidget(lbl2);
vl2->addWidget(pl);

// Create and set the main layout
QHBoxLayout mainLayout = new QHBoxLayout(this);
mainLayout->addLayout(vl1);
mainLayout->addLayout(vl2);
Run Code Online (Sandbox Code Playgroud)