I am creating a widget which contains a chess table and six buttons which are displayed in 2 rows beneath the chess table. The button rows are wider than the chess table. Chess table and buttons are in a QGridLayout. Chess table has its own sizeHint calculated from the size of the squares.
After some operations I delete the buttons and resize the widget that contains everything to its sizeHint (resize(sizeHint())
). The widget resizes properly in the vertical direction but in the horizontal direction it remains as wide as if the button rows were there. What is the problem ?
If I construct the widget only with the chess table the layout sizes the widget properly.
I am adding the code:
In the constructor of the window:
renderArea = new RenderArea(m_row,m_col,m_grid);
formLayout = new QGridLayout;
formLayout->addWidget(renderArea,0,0,1,3);
setLayout(formLayout);
In the function that adds the buttons:
addPlaneButton = new QPushButton(tr("Add plane"));
cancelButton = new QPushButton(tr("Cancel operation"));
movePlaneButton = new QPushButton(tr("Move plane"));
deletePlaneButton = new QPushButton(tr("Delete plane"));
rotatePlaneButton = new QPushButton(tr("Rotate plane"));
doneButton = new QPushButton(tr("Done"));
doneButton->setEnabled(false);
infoLabel = new QLabel(tr("Welcome to the plane editor"));
statusLabel = new QLabel();
formLayout->addWidget(statusLabel,1,0,1,3);
formLayout->addWidget(infoLabel,2,0,1,3);
formLayout->addWidget(addPlaneButton,3,0);
formLayout->addWidget(movePlaneButton,3,1);
formLayout->addWidget(deletePlaneButton,3,2);
formLayout->addWidget(rotatePlaneButton,4,0);
formLayout->addWidget(cancelButton,4,1);
formLayout->addWidget(doneButton, 4,2);
In the function that deletes everything besides the chess table:
formLayout->removeWidget(addPlaneButton);
formLayout->removeWidget(cancelButton);
formLayout->removeWidget(movePlaneButton);
formLayout->removeWidget(deletePlaneButton);
formLayout->removeWidget(rotatePlaneButton);
formLayout->removeWidget(doneButton);
formLayout->removeWidget(infoLabel);
formLayout->removeWidget(statusLabel);
delete addPlaneButton;
delete cancelButton;
delete movePlaneButton;
delete deletePlaneButton;
delete rotatePlaneButton;
delete doneButton;
delete infoLabel;
delete statusLabel;
resize(sizeHint());
The sizeHint for the chess table is calculated as:
return QSize(m_rowNo*spacing, m_colNo*spacing)+QSize(31,31);