[PyQt] Read-only QSqlRelationalTableModel

Brian Zambrano brianz at gmail.com
Mon Aug 24 17:28:42 BST 2009


Perfect....setting the flags did the job.  I have a very simple subclass
that overrides flags:

    def flags(self, index):
        return Qt.ItemIsSelectable | Qt.ItemIsEnabled

Thank you!
BZ

On Mon, Aug 24, 2009 at 2:56 AM, Sibylle Koczian <
Sibylle.Koczian at t-online.de> wrote:

>
> "Brian Zambrano" <brianz at gmail.com> schrieb:
>
> Is there a way to create a read-only QSqlRelationalTableModel?
>
> From the docs, I'm thinking that I need to create my own subclass of
> QSqlQueryModel which follow the relationships that I need.
>
> Thanks,
> BZ
>
> I think you could subclass QSqlRelationalTableModel and just override
> setData(). It should always return False. And/or override flags():
>
> def flags(self, index):
>     flags = QtSql.QSqlRelationalTableModel.flags(self, index)
>     flags ~= QtCore.Qt.ItemIsEditable
>     return flags
>
> But all this is untested! Just the opposite from making a QSqlQueryModel
> editable.
>
> On the other hand a QSqlQueryModel can use every query, so I don't quite
> know why you couldn't use it as is, with all the relationships built into
> the query?
>
> HTH
> Sibylle
>
> --
> Dr. Sibylle Koczian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090824/85f33bbd/attachment.html


More information about the PyQt mailing list