我有一个包含几个 QComboBoxes 的 QTreeWidget。如何获取 QTreeWidget 中的 QComboBox 的当前文本?
我的 QTreeWidget 看起来像这样:
ui->sensorTree
parent0
    child0    QComboBox
    child1    QComboBox
parent1
    child0    QComboBox
    child1    QComboBox
我有一个包含几个 QComboBoxes 的 QTreeWidget。如何获取 QTreeWidget 中的 QComboBox 的当前文本?
我的 QTreeWidget 看起来像这样:
ui->sensorTree
parent0
    child0    QComboBox
    child1    QComboBox
parent1
    child0    QComboBox
    child1    QComboBox
activated(QString)将信号从连接QComboBox到您选择的自定义插槽。您可以使用单个插槽来处理所有激活的命令,也可以使用多个插槽。我下面的示例使用多个插槽。
connect(parent0->child0, SIGNAL(activated(QString)), this, SLOT(child00(QString)));
connect(parent0->child1, SIGNAL(activated(QString)), this, SLOT(child01(QString)));
connect(parent1->child0, SIGNAL(activated(QString)), this, SLOT(child10(QString)));
connect(parent1->child1, SIGNAL(activated(QString)), this, SLOT(child11(QString)));
您需要为您在 中创建的每个子小部件重复该过程QTreeView,或者使用一个QSignalMapper类来捆绑所有信号。