QTableWidget with QComboBox
I have a QTableWidget with multiple rows (not a specific number) and 7 columns.
2nd to 7th column are filled with comboboxes in every row.
Everytime the selection (index) is changed on the 2nd column comboboxes I would like to add items to all the comboboxes in the same row.
The initial ideia was to update the comboboxes (3rd to 7th column) everytime the index of the combobox on the 2nd column is changed. Although I didn't managed to make it work with "itemChanged".
Then I tried with the signal "currentCellChanged" but it didn't work.
My ideia was to read the current text of the combobox on the 2nd column when a cell between 2nd and 7th column was selected.
From what I could understand when I switch between a cell with a combobox and another cell with a combobox it doesn't detect a cell change. Although if I switch from a cell with a combobox to a cell with text (1st column) it does detect.
My solution was to update this by clicking the 1st column after changing the 2nd column combobox index. But this solution isn't great. I need a better solution.
I would appreciate if someone could provide a really simple example with code. Most likely I will be able to adapt it to my situation.
Image of QTableWidget with QComboBox
(I couldn't take a screenshot, sorry)
As you can see when the option is AND I want to add a few items (such as "Botao 1", "Botao 2", "Botao 3", etc) to the comboboxes of the same row.. When the option is "On" I want to add other items.
Welcome to Devnet,
If possible can you post an image of your tableView with the comboboxes, It will be easy to understand the requirement :)
Edited. Thank you ;)
How do you construct comboboxes?
Do you assign it to the cell with QTableWidget ::setCellWidget?
If yes these combo boxes are completely independent widgets unrelated to QTableWidget.
So no itemChanged or any other table related signal is going to be sent when you manipulate with cell widget (unless you do it yourself).
In reality using cell widgets screw your table view navigation and selection.
I would highly recommend to avoid cell widget approach and leave it only for very simple cases.
In your case it probably would be better to use column specific delegates.
Recommendations from the top of my head:
- find is a Spin Box Delegate example in documentation.
- Make your own subclass similar to in example.
- set autoFillBackground(true) to your editor widget in the createEditor method.
- Set openPersistentEditor on your view's for desired rows/columns.