PDA

View Full Version : Warning when dynamically recreating a QGridLayout



nilot
30th November 2016, 13:34
Hello,

The goal of my class MyDialog is to display dynamically 2 or 10 checkboxes using a gridlayout. If the number of checkboxes changes, first
I empty the gridlayout (function clearLayout) and then I insert the desired number of checkboxes.

Unfortunately an annoying warning is displayed (I use qt 5.7 on windows) after the call of adjustSize():

setGeometry: Unable to set geometry 22x22+2481+481 on QWidgetWindow/'MyDialogClassWindow'. Resulting geometry: 95x22+2481+481 (frame: 8, 30, 8, 8, custom margin: 0, 0, 0, 0, minimum size: 22x22, maximum size: 16777215x16777215).

Do you understand why there is such a warning ?
Thank you



#include "mydialog.h"

MyDialog::MyDialog()
:QDialog()
{
_value = 2;
_layout = new QGridLayout;
setLayout(_layout);
createDisplay();
}

MyDialog::~MyDialog(){}

// remove all the widgets of layout
void MyDialog::clearLayout(QLayout* layout)
{
if(!layout) return;
while (QLayoutItem* item = layout->takeAt(0))
{
if (QWidget* widget = item->widget()){
widget->deleteLater();
}

if (QLayout* childLayout = item->layout())
clearLayout(childLayout);
delete item;
}
}

void MyDialog::createDisplay()
{
clearLayout(layout());

_comboBoxType = new QComboBox();
_comboBoxType->addItem("2", 2);
_comboBoxType->addItem("10", 10);
if(_value == 2)
{
_comboBoxType->setCurrentIndex(0);
}else
{
_comboBoxType->setCurrentIndex(1);
}
_layout->addWidget(_comboBoxType, 0, 0);
connect(_comboBoxType, SIGNAL(currentIndexChanged(int)), this, SLOT(setValue()));

for(int i=0; i<_value; ++i)
{
QCheckBox *w = new QCheckBox("Value :", this);
_layout->addWidget(w, i+1, 0);
}
adjustSize();
}

void MyDialog::setValue()
{
_value = _comboBoxType->currentData().toInt();
createDisplay();
}

12232
12233