Question

I have a QTreeWidget that contains several QComboBoxes. How can I get the current text of a QComboBox that is in the QTreeWidget?

My QTreeWidget looks something like this:

ui->sensorTree

parent0
    child0    QComboBox
    child1    QComboBox

parent1
    child0    QComboBox
    child1    QComboBox
Was it helpful?

Solution

Connect the activated(QString) signal from the QComboBox to a custom slot of your choosing. You can either use a single slot to handle all the activated commands, or multiple slots. My example below uses multiple slots.

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)));

You'll need to repeat the process for each child widget that you make in the QTreeView, or use a QSignalMapper class to bundle all the signals.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top