[PySide] Form dialog subclassing QDialog

Jérôme jerome at jolimont.fr
Wed Mar 26 18:08:43 CET 2014

Le 2014-03-26 16:49, Jérôme a écrit :

> Thanks for any advice. The more I think of it, the mode it seems that
> the only way is to add a (hidden or not) ID column.

I just did this.

            # Get selected items. If none, exit.
            selected = self.tableView.selectedIndexes()
            # Get selected row in model from selection in proxy
            # (Note: all elements are on the same row, 
            # thanks to
            selected_row =

            # Get ID of item corresponding to selected row (ID is column
            ID = self.model.item(selected_row, 0).text()

            # Get corresponding index in model.items list
            index = self.model.findIndex(ID)

findIndex is a method of my model:

    def findIndex(self, ID):
        ID_list = [item.ID for item in self._items]
        if ID not in ID_list:
            return None
        return ID_list.index(ID)

and now, I'm realizing that the order of the row was not messed up, just
modified by the proxying.

The quick solution was to just write

            index = self.proxy_model.mapToSource(selected[0]).row()

instead of

            index = selected[0].row()


I guess... I've learned something today (TM) [1].

Thanks for reading anyway.

> Overall, I think my problems are due to the fact that I don't rely
> solely on Qt's Model/View architecture: I keep the data in this
> self.persons attribute list.
> As we said in another message in this thread, these lists could be
> removed and the data could be kept only in QStandardItem instances, but
> then I'd need to be able to store everything in this form, even data
> that I don't know how and don't want to display in views. My approach is
> different, I store everything in python classes, and when I need a user
> interaction, I set a model to display what I want to display, and this
> only, and I trash that model when I'm done.

Perhaps I should use a TreeModel to fit all the data but for now I'll
stick to this approach.

[1] http://www.cs.berkeley.edu/~smaji/southpark.html


More information about the PySide mailing list