我有一个带有多个复选框项目的组合框,我需要能够遍历它们并确定它们是否经过检查或更合适,一旦检查项目,就会触发事件但是我不能似乎让信号/插槽组合正常工作。
以下是我的一些代码:
void MainWindow::setupQueryBuilder(Ui::MainWindow* ui)
{
QStandardItemModel* assessmentModel = new QStandardItemModel(3, 1);
QStandardItem* assessmentPleaseSelect = new QStandardItem();
QStandardItem* assessmentVisionScreening = new QStandardItem();
QStandardItem* assessmentHearingAssessment = new QStandardItem();
QStandardItem* assessmentDevelopmentalAssessment = new QStandardItem();
assessmentPleaseSelect->setText("Please Select...");
assessmentPleaseSelect->setFlags(Qt::ItemIsEnabled);
assessmentPleaseSelect->setData(Qt::CheckStateRole);
assessmentVisionScreening->setText("Vision Screening");
assessmentVisionScreening->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
assessmentVisionScreening->setData(Qt::Unchecked, Qt::CheckStateRole);
assessmentHearingAssessment->setText("Hearing Assessment");
assessmentHearingAssessment->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
assessmentHearingAssessment->setData(Qt::Unchecked, Qt::CheckStateRole);
assessmentDevelopmentalAssessment->setText("Developmental Assessment");
assessmentDevelopmentalAssessment->setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
assessmentDevelopmentalAssessment->setData(Qt::Unchecked, Qt::CheckStateRole);
assessmentModel->insertRow(0, assessmentPleaseSelect);
assessmentModel->insertRow(1, assessmentVisionScreening);
assessmentModel->insertRow(2, assessmentHearingAssessment);
assessmentModel->insertRow(3, assessmentDevelopmentalAssessment);
ui->SearchAssessmentSelect->setModel(assessmentModel);
}
答案 0 :(得分:1)
我没有试过这个,但是通过查看文档signal
QStandardItemModel
名为itemChanged(QStandardItem *item)
。您要做的是创建一个名为slot
的{{1}} modelItemChanged(QStandardItem *item)
和connect
个connect(assessmentModel, SIGNAL(itemChanged(QStandardItem *)), this, SLOT(modelItemChanged(QStandardItem *)))
。
这应该将模型设置为在slot
更改时触发QStandardItem
,并且它会传递指向已更改项的指针。在modelItemChanged(QStandardItem *item)
函数中,您可以查询QStandardItem *item
以查看它所处的状态。