QGroupBox *groupBoxChoiceRegion = new QGroupBox(dialog); groupBoxChoiceRegion->setTitle("Выбор региона:"); groupBoxChoiceRegion->setObjectName("groupBoxChoiceRegion"); QGridLayout *gridLayoutChoiceRegion = new QGridLayout(groupBoxChoiceRegion); gridLayoutChoiceRegion->setObjectName("gridLayoutChoiceRegion"); gridLayoutChoiceRegion->setSizeConstraint(QLayout::SetFixedSize);
QGroupBox *groupBoxChoiceRegion = dialog->findChild<QGroupBox *>("groupBoxChoiceRegion"); groupBoxChoiceRegion->show(); QGridLayout *gridLayoutChoiceRegion = dialog->findChild<QGridLayout *>("gridLayoutChoiceRegion"); QObjectList childrensGroupBoxChoiceRegion = groupBoxChoiceRegion->children(); foreach (QObject *object, childrensGroupBoxChoiceRegion) { if (object->objectName() != "gridLayoutChoiceRegion") { QPushButton *pushButton = qobject_cast<QPushButton*>(object); pushButton->deleteLater(); } } int columnCount = 5; for (int i = 0, row = 0, column = 0; i < cities.count(); i++) { City city = cities.at(i); QPushButton *pushButton = new QPushButton(city.region, groupBoxChoiceRegion); if (i%columnCount == 0 && i != 0) { row += 1; column += columnCount; } gridLayoutChoiceRegion->addWidget(pushButton, row, i - column); }
QObjectList childrensGroupBoxChoiceRegion = groupBoxChoiceRegion->children(); qDebug() << endl << "childrensGroupBoxChoiceRegion" << childrensGroupBoxChoiceRegion; if (childrensGroupBoxChoiceRegion.count()-1 > 0) { QObject *object = childrensGroupBoxChoiceRegion.at(1); QPushButton *pushButton = qobject_cast<QPushButton*>(object); qDebug() << endl << "pushButton->text()" << pushButton->text(); if (!cities.isEmpty()) { City city = cities.at(0); qDebug() << "city.region" << city.region; if (pushButton->text() != city.region) { foreach (QObject *object, childrensGroupBoxChoiceRegion) { if (object->objectName() != "gridLayoutChoiceRegion") { QPushButton *pushButton = qobject_cast<QPushButton*>(object); pushButton->deleteLater(); } } qDebug() << endl << "childrensGroupBoxChoiceRegion deleteLater()" << childrensGroupBoxChoiceRegion; int columnCount = 5; for (int i = 0, row = 0, column = 0; i < cities.count(); i++) { City city = cities.at(i); QPushButton *pushButton = new QPushButton(city.region, groupBoxChoiceRegion); //connect(pushButton, SIGNAL(clicked()), this, SLOT(selectRegion())); //gridLayoutChoiceRegion->addWidget(pushButton); if (i%columnCount == 0 && i != 0) { row += 1; column += columnCount; } gridLayoutChoiceRegion->addWidget(pushButton, row, i - column); } qDebug() << endl << "groupBoxChoiceRegion posle" << groupBoxChoiceRegion->children(); } } else { foreach (QObject *object, childrensGroupBoxChoiceRegion) { if (object->objectName() != "gridLayoutChoiceRegion") { QPushButton *pushButton = qobject_cast<QPushButton*>(object); pushButton->deleteLater(); } } qDebug() << endl << "childrensGroupBoxChoiceRegion deleteLater()" << childrensGroupBoxChoiceRegion; } } else { int columnCount = 5; for (int i = 0, row = 0, column = 0; i < cities.count(); i++) { City city = cities.at(i); QPushButton *pushButton = new QPushButton(city.region, groupBoxChoiceRegion); //connect(pushButton, SIGNAL(clicked()), this, SLOT(selectRegion())); //gridLayoutChoiceRegion->addWidget(pushButton); if (i%columnCount == 0 && i != 0) { row += 1; column += columnCount; } gridLayoutChoiceRegion->addWidget(pushButton, row, i - column); } qDebug() << endl << "groupBoxChoiceRegion posle" << groupBoxChoiceRegion->children(); }
QPushButton *pushButton = qobject_cast<QPushButton*>(object);pushButton->deleteLater();