Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QGridLayout with different size of cells

Tags:

c++

grid

qt

I'm trying to set a QGridLayout with four widget as in the image below: Goal

however what I've managed with QGridLayout as of now is: Current situation

I don't see how I can set the size of the row different for column 0 and 1. Maybe QGridLayout is not the right way of doing it but I don't know of any other widget that would do the trick. Does anyone have any idea how to achieve this?

like image 200
maelorn Avatar asked Feb 12 '23 15:02

maelorn


2 Answers

I would use vertical and horizontal layouts instead of the grid layout. So you need two vertical layouts and horizontal one:

// 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);
like image 94
vahancho Avatar answered Feb 22 '23 09:02

vahancho


I don't think grids are the way to go here indeed...

You could try making a horizontal layout of 2 QFrames, in which you set a vertical layout each with the two widgets of that "column"

like image 28
MultiVAC Avatar answered Feb 22 '23 08:02

MultiVAC