[PyQt] Synchronized scrolling between two tables
Wolfgang Rohdewald
wolfgang at rohdewald.de
Wed Nov 2 14:27:36 GMT 2011
Am Mittwoch, 2. November 2011, 06:23:36 schrieb Nader Abedrabbo:
> If their is a way to disable certain columns in a table from being selected,
> I would appreciate if you can guide me to it.
you can define you own model, deriving from a Qt standard model,
and override flags(). In the link I gave you there is a file rulesetselector.py
which defines a tree view where some items can be edited in
different ways (combobox, text, numbers, checkboxes). Your table
view should be easier to implement.
def flags(self, index): # pylint: disable=R0201
"""tell the view what it can do with this item"""
if not index.isValid():
return Qt.ItemIsEnabled
column = index.column()
item = index.internalPointer()
content = item.rawContent
checkable = False
if isinstance(content, Ruleset) and column in (0, 3):
mayEdit = True
elif isinstance(content, Rule):
mayEdit = column in [0, 1, 2, 3]
checkable = column == 1 and content.parType is bool
else:
mayEdit = False
mayEdit = mayEdit and not isinstance(item.ruleset(), PredefinedRuleset)
result = Qt.ItemIsEnabled | Qt.ItemIsSelectable
if mayEdit:
result |= Qt.ItemIsEditable
if checkable:
result |= Qt.ItemIsUserCheckable
return result
More information about the PyQt
mailing list