I'm developing a little game in C++ Qt 4.6.3 and I stumbled upon a layout-issue. The layout I'm looking for is a 3x3 QGridLayout of which the central cell (1,1) holds the main widget (it's a board game). The (0,1)-cell should hold a QLabel displaying whos turn it is, the (1,0) and (1,2) cells are subdivided into QVBoxLayouts to hold a maximum of 3 scoreboards, and the (2,1)-cell also holds some kind of QLabel.
This is what I've got so far:
QGridLayout *mainLayout = new QGridLayout(this);
QVBoxLayout *leftLayout = new QVBoxLayout;
QVBoxLayout *rightLayout = new QVBoxLayout;
mainLayout->addLayout(leftLayout, 1, 0, AlignTop);
mainLayout->addWidget(topText, 0, 1, AlignCenter);
mainLayout->addWidget(board, 1, 1);
mainLayout->addLayout(bottomText, 2, 1, AlignCenter);
mainLayout->addLayout(rightLayout, 1, 2, AlignTop);
Now, on MS Windows (laptop of my GF) I solved this by reimplementing the resizeEvent()
function:
void Game::resizeEvent(QResizeEvent *)
{
mainLayout->setRowMinimumHeight(1, 0.8 * height());
mainLayout->setColMinimumWidth(1, 0.8 * height());
// some other stuff
}
This worked fine! However, on Unix there seems to be a problem (or could it be due to a version difference? 4.6 vs 4.8). On calling the setRowMininmumHeight()
method, it seems that another resize-event is issued, resulting in a recursive call! I want my application to work on both platforms, so clearly I had to find another solution. I fiddled around with setRowStretch()
and setColStretch()
but neither of those had the desired result. I tried all sorts of combinations but now I am quite stuck...
Does anyone have a solution to this seemingly easy problem?