我是一个新手 Qt 开发人员(差不多一个月),我在网上搜索了我的问题的解决方案,但我一无所获。也许,我不知道如何或问什么。所以,我将介绍这几天困扰我的问题。
我使用以下命令动态创建表单:
QWidget *window = new QWidget;
QGridLayout *headerlayout = new QGridLayout;
QGridLayout *bodylayout = new QGridLayout;
QGridLayout *layout = new QGridLayout;
QLabel *countrylabel = new QLabel;
QComboBox *countrycombo = new QComboBox;
country << "" << "England" << "Germany" << "Greece" << "Italy" << "Netherlands";
countrycombo->addItems(country);
countrylabel->setText("Χώρα");
connect(countrycombo, SIGNAL(currentIndexChanged(int)), this, SLOT(countryselected(int)));
//Suppose there 8 more widgets here
headerlayout->addWidget(countrylabel,0,0);
headerlayout->addWidget(countrycombo,0,1);
//Here is the body part
QLabel *label0 = new QLabel;
QLabel *label1 = new QLabel;
label0->setText("LABEL1");
label1->setText("<b>LABEL2</b>");
//suppose there are 10 labels here and 8 more of the commands below.
bodylayout->addWidget(label0,0,0);
bodylayout->addWidget(label1,0,1);
//HERE IS the CLEVER PART
for (int i=1;i<9;i++){
QComboBox *combo1 = new QComboBox;
QSpinBox *spin1 = new QSpinBox;
QSpinBox *spin2 = new QSpinBox;
QSpinBox *spin3 = new QSpinBox;
bodylayout->addWidget(combo1,i,0);
bodylayout->addWidget(spin1,i,1);
bodylayout->addWidget(spin2,i,2);
bodylayout->addWidget(spin3,i,3);
}
//END OF CLEVER PART
//Bring them all together
layout->addLayout(headerlayout,1,10,0);
layout->addLayout(bodylayout,10,10,0);
window->setLayout(layout);
使用这段代码,我创建了一个漂亮的动态表单,无需担心。我的问题由以下问题描述:
-我如何访问 CLEVER 部分中的小部件以更改或读取它们的属性(例如,组合框的当前索引、旋转框的值等)。我想要做的是选择 countrycombo(在顶部),然后根据第一个组合值(此处未描述,它在 headerlayout 中)更改第二个组合的值,然后更改值在 CLEVER 部分内的组合框中,并从 spinboxes 中“读取”值,以使一些 SQL 变得“神奇”。
我还阅读了有关 SIGNAL 和 SLOT 的信息,但问题仍然存在。CLEVER 部分中的对象名称或地址。
我阅读了有关创建 QList 的信息,但我不知道这是否是个好主意。
谢谢尼克