I have a QTreeWidget which contains two columns and some rows. I would like to set a flag so that if an item in the second column is either a zero or empty, it cannot be edited. If the item clicked is not numeric, it will be shown with a red text.
My code:
def qtree_check_item(self, item, column):
item.setFlags(QtCore.Qt.ItemIsEnabled)
if column == 1:
if item.text(1) != '0':
item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
if not item.text(1).isnumeric():
item.setForeground(1, QtGui.QBrush(QtGui.QColor("red")))
This works if the item is zero. If I replace:
if item.text(1) != '0':
with
if item.text(1) != '':
This works for empty strings. But if I combine both using:
if item.text(1) != '0' or item.text(1) != '':
The flags are not set. What am I doing wrong?
and
rather thanor
. – G.M.and
is required in this case as I assumedor
would have been more logical? Also please post your comment as an answer :) – Joseph