【问题标题】:Qt get QComboBox->currentText within QTreeWidgetQt 在 QTreeWidget 中获取 QComboBox->currentText
【发布时间】:2013-09-15 22:00:36
【问题描述】:

我有一个包含多个 QComboBox 的 QTreeWidget。如何获取 QTreeWidget 中的 QComboBox 的当前文本?

我的 QTreeWidget 看起来像这样:

ui->sensorTree

parent0
    child0    QComboBox
    child1    QComboBox

parent1
    child0    QComboBox
    child1    QComboBox

【问题讨论】:

    标签: qt qtreewidget qcombobox


    【解决方案1】:

    将来自QComboBoxactivated(QString) 信号连接到您选择的自定义插槽。您可以使用单个插槽来处理所有激活的命令,也可以使用多个插槽。我下面的示例使用了多个插槽。

    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 类来捆绑所有信号。

    【讨论】:

      猜你喜欢
      • 2013-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-15
      • 1970-01-01
      相关资源
      最近更新 更多