我想創建一個QWizard。我需要在第一個窗口中使用QRadioButton和QComboBox的組合,並在第二個窗口中使用QCheckBox和QComboBox。QWizard QCheckBox,QRadioButton和QComboBox:信號/插槽和SignalMapping - 所需信息
在第一個窗口中,作爲每個RadioButton的文本傳出的信息來自指定路徑中的目錄,而ComboBox列表是RadioButton目錄內目錄的迭代。
在第二個窗口中,過程與上述相同,而不是單選按鈕,但會從另一個目錄路徑中複選框。
單選按鈕和組合框與信號和插槽相互依賴,如果選中一個單選按鈕,則必須激活其相應的組合框,並且如果選擇了下一個無線電,則必須禁用第一個無線電。但是這並沒有發生,Combobox列表每增加一次,當我檢查它時,相應的組合框也沒有被禁用。
這裏是我的代碼:
void SelectOption::initializeUi()
{
this->setWindowTitle("Window-1");
QGridLayout *gridLayout1 = new QGridLayout();
gridLayout1->setMargin(5);
gridLayout1->setSpacing(5);
QSignalMapper* signalMapper = new QSignalMapper();
for(int i = 0; i < list.size(); i++){
radioButton[i] = new QRadioButton();
radioButton[i]->setText(softwareList[i]);
signalMapper->setMapping(radioButton[i], i);
gridLayout1->addWidget(radioButton[i], i/1, i%1);
connect(radioButton[i], SIGNAL(clicked()),signalMapper, SLOT(map()));
}
connect(signalMapper, SIGNAL(mapped(const int &)),this, SIGNAL(radioChecked(const int &)));
connect(this, SIGNAL(radioChecked(const int &)),this, SLOT(test(const int)));
QGridLayout *gridLayout2 = new QGridLayout();
gridLayout2->setMargin(5);
gridLayout2->setSpacing(5);
for(int j = 0; j < list.size(); j++){
comboBox[j] = new QComboBox();
comboBox[j]->setDisabled(true);
gridLayout2->addWidget(comboBox[j], j/1, j%1);
}
QPushButton *nextButton = new QPushButton("Next >");
nextButton->setDefault(true);
connect(nextButton, SIGNAL(clicked()), this, SLOT(showMainPage()));
QPushButton *backButton = new QPushButton("< Back");
backButton->setDefault(true);
connect(backButton, SIGNAL(clicked()), this, SLOT(showSelectOS()));
QPushButton *cancelButton = new QPushButton("Cancel");
cancelButton->setDefault(true);
connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancel()));
QHBoxLayout *hboxlayout;
hboxlayout = new QHBoxLayout();
hboxlayout->addLayout(gridLayout1);
hboxlayout->addLayout(gridLayout2);
QHBoxLayout *layout;
layout = new QHBoxLayout();
layout->addStretch(10);
layout->addWidget(nextButton);
layout->addWidget(backButton);
layout->addWidget(cancelButton);
layout->addStretch(10);
QVBoxLayout *mainLayout;
mainLayout = new QVBoxLayout();
mainLayout->addLayout(hboxlayout);
mainLayout->addLayout(layout);
ui->centralwidget->setLayout(mainLayout);
}
void SelectOption::test(const int id) // REMEMBER
{
if(radioButton[id]->isChecked()){
comboBox[id]->setEnabled(true);
comboBox[id]->addItem(" Select anyone ");
QString path = qApp->applicationDirPath() + "/list/" + radioButton[id]->text();
QDir dir;
dir.cd(path);
dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
QFileInfoList list = dir.entryInfoList();
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
comboBox[id]->addItem(fileInfo.fileName());
}
}else{
comboBox[id]->clear();
comboBox[id]->setDisabled(true);
}
}
感謝您的回覆,但QButtonGroup不再可用我想?相反,我必須使用QGroupBox?你可以在我的代碼中展示給我... – 2013-04-09 13:49:22
'QButtonGroup'和'QGroupBox'是兩個完全不同的東西。你爲什麼認爲它不可用?你使用Qt5嗎?這裏是:http://qt-project.org/doc/qt-5.0/qtwidgets/qbuttongroup.html – Amartel 2013-04-09 13:53:42
再次感謝,我恐怕我不知道QRadioButtons的QButtonGroup的用法,請你幫我代碼?? – 2013-04-09 14:05:41