Я пытаюсь расположить окно (все в коде) с QGridLayout
. Я могу добавить виджеты в макет, и они отображаются в моем окне, но я не могу понять, как правильно их изменить размер. Вот что я хотел бы
[Leftmost][--------Center---------][Rightmost]
Это 3 "окна" моего окна (все три списка). Левый и правый должны иметь статическую ширину и охватывать их соответствующие стороны, а центр должен расширяться, чтобы заполнить ширину по мере того, как окно увеличивается (или сжимается).
Некий код:
// Create the subviews, add them to a grid layout, and set the layout to the window.
QTableView *list = new QTableView(0);
list->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QTableView *flashList = new QTableView(0);
flashList->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QPushButton *infoButton = new QPushButton("Info!");
QPushButton *flashFeedsButton = new QPushButton("Flashfeeds");
QGridLayout *gridLayout = new QGridLayout;
// Set the minimum widths for all three columns of the grid
gridLayout->setColumnMinimumWidth(GridColumnFirst, 300);
gridLayout->setColumnMinimumWidth(GridColumnSecond, 300);
gridLayout->setColumnMinimumWidth(GridColumnThird, 300);
// Set the minimum heights for all rows of the grid
int headerFooterHeight = 44;
gridLayout->setRowMinimumHeight(GridRowFirst, headerFooterHeight);
gridLayout->setRowMinimumHeight(GridRowSecond, 200);
gridLayout->setRowMinimumHeight(GridRowThird, headerFooterHeight);
// Set the stretch factors
gridLayout->setColumnStretch(GridColumnFirst, 1);
gridLayout->setColumnStretch(GridColumnFirst, 2);
gridLayout->setColumnStretch(GridColumnThird, 1);
gridLayout->addWidget(list, 1, 0, Qt::AlignLeft);
gridLayout->addWidget(flashList, 1, 1, Qt::AlignCenter);
gridLayout->addWidget(infoButton, 0, 3, Qt::AlignRight);
gridLayout->addWidget(flashFeedsButton, 0, 1, Qt::AlignLeft);
_mainWindow->setLayout(gridLayout);
(Как вы могли бы сказать, в конечном итоге это будет сетка 9x9, но суть остаётся, я пытаюсь получить в среднем ряду (GridRowSecond
) растянутые столбцы).
Сами ряды просто расширяются. Кажется, проблема в том, что виджеты в каждой ячейке расширяются, чтобы занять место, содержащее их. Как мне это сделать? (также по вертикали мой список расширяется правильно, но не по горизонтали).