0

I have a QTreeWidget with several QComboBoxes as QTreeWidgetItems. I am trying to find a way to get the current QTreeWidget row of the selected QComboBox. ui->sensorTree is the QTreeWidget. My tree looks something like this:

parent0
    child0    QComboBox0
    child1    QComboBox1
parent1
    child0    QComboBox0    QComboBox0
    child1    QComboBox1    QComboBox1

So if QComboBox0 was selected I would want to return 0.

Update:

int index = ui->sensorTree->currentIndex().row();

This gives me the correct row. The problem now is that the row does not have to be selected to change the QComboBox. What I need is to connect QComboBox.indexChanged to pass the row the ComboBox is in, and the current ComboBox text of all ComboBoxes in the row.

Jared Price
  • 4,489
  • 7
  • 40
  • 70

1 Answers1

0

I got it to work. I ended up just creating my own custom class which inherited QComboBox and I just added a constructor that passed in an extra parameter that had the row number. Then I created a custom signal that passed the current text of the combobox and the row which was obtained from the row data passed in by the constructor.

Jared Price
  • 4,489
  • 7
  • 40
  • 70
  • And what will be, if some row above will be removed? Then your index became invalid. You should pass QPersistentModelIndex instead of row number – Dmitry Sazonov Sep 13 '13 at 07:02
  • In my case it will work. In my application rows are only removed if the entire table is rebuilt and in that case the comboboxes are rebuilt as well. – Jared Price Sep 13 '13 at 14:37