QTableview index issue
-
wrote on 12 Jun 2018, 15:48 last edited by
Using PyQt5, one feature of my application is that there is a QTableView that dynamically increases the number of rows it has. Each column has a different purpose, widgets, text entries, etc. One such columns has QComboBoxes with 3-4 entries (but potentially more in the future). What I want to be able to do is when the user selects one of the indices from the combo box, I want the adjacent cell (same row, different column) text entry to be disabled. The problem is that all of the signals from QComboBox point to the index of the item selected in the combo box itself, so I have no way of knowing which row (in the whole table) is selected, therefore after I determine which index in the combo box was changed (with currentIndexChanged), I don't know which row in the table to apply the change to. Because there is a dynamic number of rows, I can't just make a new signal for each new row. Any help would be appreciated.
Thanks,
kprice -
wrote on 12 Jun 2018, 15:51 last edited by
Don't use
setItemWidget
.Subclass
QStyledItemDelegate
to use a combobox and set that delegate to the column you want. then conncet to thedataChanged
signal of your model and if the changed index is in the column with the combos decide what to do -
wrote on 12 Jun 2018, 16:20 last edited by
Thank you so much.
-
wrote on 12 Jun 2018, 16:30 last edited by
On and unrelated question, when setting flags, for instance ".setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable)" and "setFlags(content.flags() & ~QtCore.Qt.ItemIsEditable & ~QtCore.Qt.ItemIsSelectable)" , are the | and & characters acting like logical ORs and ANDs? Like does it take the current value of of the flags and use that to compute the values of all of them? For instance, in the first example, if currently ItemIsEditable is true and the ItemIsSelectable is false, would it set them both to true b/c they're ORed?
-
On and unrelated question, when setting flags, for instance ".setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable)" and "setFlags(content.flags() & ~QtCore.Qt.ItemIsEditable & ~QtCore.Qt.ItemIsSelectable)" , are the | and & characters acting like logical ORs and ANDs? Like does it take the current value of of the flags and use that to compute the values of all of them? For instance, in the first example, if currently ItemIsEditable is true and the ItemIsSelectable is false, would it set them both to true b/c they're ORed?
Lifetime Qt Championwrote on 12 Jun 2018, 16:43 last edited by mrjj 6 Dec 2018, 16:43@kprice
Yes its OR AND , NOT (negate)
( i assume its the same for python as for c++ :)so
setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable)
Sets both
setFlags(content.flags() & ~QtCore.Qt.ItemIsEditable & ~QtCore.Qt.ItemIsSelectableTake current flags and mask out both ItemIsEditable and ItemIsSelectable
(if set) -
On and unrelated question, when setting flags, for instance ".setFlags(QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsSelectable)" and "setFlags(content.flags() & ~QtCore.Qt.ItemIsEditable & ~QtCore.Qt.ItemIsSelectable)" , are the | and & characters acting like logical ORs and ANDs? Like does it take the current value of of the flags and use that to compute the values of all of them? For instance, in the first example, if currently ItemIsEditable is true and the ItemIsSelectable is false, would it set them both to true b/c they're ORed?
wrote on 12 Jun 2018, 16:43 last edited byThey are bitwise operators AND/OR
1/6