0

I'm trying to do this with PySide 1.2 and Python 2.73.

Here's my equivalent code:

class AssetTableModel(QtCore.QAbstractTableModel):

    # ...

    def data(self, index, role):
        if not index.isValid():
            return None

        item = self.getItemFromIndex(index)
        if role == QtCore.Qt.DisplayRole or role == QtCore.Qt.EditRole:
            return item.qt_data(index.column())

        if role == QtCore.Qt.ForegroundRole:
            color = item.qt_foreColor()
            if color is None:
                # the following line is causing the error
                return QtCore.QAbstractTableModel.data(self, index, role)

            return QtGui.QBrush(color)

This is the error I'm obtaining:

NotImplementedError: pure virtual method 'QAbstractItemModel.data()' not implemented.

I tried returning QtCore.QAbstractItemModel.data(self, index, role) and it still reports an error. I'm doing this sort of thing for Delegates without an issue, and it seems to follow what I'm seeing in the above C++ example.

What should I be doing instead if this is indeed unsupported? I know I can change the condition to:

if role == QtCore.Qt.ForegroundRole and item.qt_foreColor():

However let's say I'd like to catch the Style color and modify it (change the alpha or darken). How do I go about this in PySide?

Community
  • 1
  • 1
Klaudikus
  • 382
  • 3
  • 12
  • The abstract models don't have this method, because they are meant to be reimplemented. Have you tried returning None, an empty QVariant or QtGui.QBrush() ? – mdurant Oct 14 '14 at 17:39
  • @mdurant. They obviously do have the methods, otherwise `AttributeError` would be raised. However, unlike the C++ versions, the pyside/pyqt wrappers raise `NotImplementedError` rather than just returning `None`. The pyqt error message is a bit more informative: `QAbstractItemModel.data() is abstract and must be overridden`. – ekhumoro Oct 14 '14 at 19:31
  • Nevertheless, they are not intended to be used in the base abstract class, but subclassed and reimplemented. – mdurant Oct 14 '14 at 19:45
  • @mdurant. Agreed. It's just that the [C++ example](http://stackoverflow.com/a/1401533/984421) the OP is trying to port to pyside *does* call the base-class method, and I was trying to point out the differences. – ekhumoro Oct 14 '14 at 20:04
  • In the latter part of the question I ask how it would be possible to catch the existing foreground role from within the data method in order to modify it from criteria... is this possible? – Klaudikus Oct 15 '14 at 21:11
  • @mdurant I have tried, but a QtGui.QBrush() does not capture the current color inherited by the Style. Ideally I would have captured the foreground role brush/color and modified it based on data criteria. For instance lighten/darken based on some of the corresponding data properties. This is preferable because the app Style is inherited from the platform it is run on and can vary. It would have been a way to standardize the foreground role without hard-coding color values. – Klaudikus Oct 16 '14 at 01:13
  • Shouldn't you retrieve the application or parent widget's palette or style sheet, e.g., `parent.styleSheet()` – mdurant Oct 16 '14 at 13:55

0 Answers0