Я пытаюсь разметить окно (все в коде) с помощью 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
) для получения эластичных столбцов).
Сами строки расширяются нормально. Проблема, похоже, заключается в том, чтобы виджеты в каждой ячейке расширялись, чтобы занять свое содержащееся пространство. Как мне это сделать? (также по вертикали мой список расширяется правильно, но не по горизонтали).