ich habe zahlreiche comboBoxes in einem GridLayout angeordnet und versuche jetzt auf einzelne Elemente abhängig von Spalte und Zeile zuzugreifen. Allerdings stoße ich dabei auf Probleme.
Folgendes Beispiel soll mein Problem verdeutlichen:
Code: Alles auswählen
#include <QApplication>
#include <QGridLayout>
#include <QComboBox>
int main(int argc, char** argv){
QApplication app(argc, argv);
QWidget *win = new QWidget;
QGridLayout *layout = new QGridLayout(win);
for (int i = 0; i < 10; i++){
QComboBox *mybox = new QComboBox;
mybox->addItem("Test");
mybox->addItem("Test2");
layout->addWidget(mybox, i / 2, i % 2);
}
layout->itemAtPosition( 0, 0 )->widget()->findChild<QComboBox *>()->setCurrentIndex(1);
win->show();
return app.exec();
}