ウィンドウを(すべてコードで)レイアウトしようとしていますQGridLayout
. ウィジェットをレイアウトに追加してウィンドウに表示することはできますが、サイズを適切に変更する方法がわかりません。これが私が欲しいものです
[Leftmost][--------Center---------][Rightmost]
これらは、私のウィンドウの 3 つの「ペイン」です (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);
GridRowSecond
(お分かりかもしれませんが、これは最終的には 9x9 のグリッドになりますが、要点は残ります。中央の行 ( ) に伸縮性のある列を持たせようとしています)。
行自体は問題なく展開されます。問題は、各セルのウィジェットを拡張して、それらを含むスペースを占有しているようです。どうすればいいですか?(また、垂直方向にはリストが適切に拡張されていますが、水平方向には拡張されていません)。