Add additional line to QTableView object at a given position
<p>In my Gui I creats a QTableView with a QStandardItemModel and I would like to add either an additional row or column at a given position.</p>

<pre><code>class Output(object):
    def __init__(self):
        ''' '''
        self.tabs = QtGui.QTabWidget()
        self.group_box = QtGui.QGroupBox('Example')

    def run(self):
        form_layout = QtGui.QFormLayout(self.group_box)
        self.tabs.addTab(self.__genTable(),"Tab 1")
        self.tabs.addTab(self.__genTable(),"Tab 2")

        form_layout.addWidget(self.tabs)

        return self.group_box

    def __genTable(self):
        table_view = QtGui.QTableView()

        table_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        table_view.customContextMenuRequested.connect( self.__openMenu )

        table_view.setSelectionBehavior( QtGui.QTableView.SelectItems )
        table_view.setModel(QtGui.QStandardItemModel(4, 2))

        return table_view

    def __openMenu(self, position):
        menu = QtGui.QMenu()
        sub_menu_row = QtGui.QMenu("Row")
        menu.addMenu(sub_menu_row)
        addRowBelowAction = sub_menu_row.addAction("add Row below")
        action = menu.exec_(QtGui.QCursor.pos())

        if action == addRowBelowAction:
            idx = self.tabs.currentWidget().selectionModel().currentIndex()
            for i in range(self.tabs.count()):
                model = self.tabs.widget(i).selectionModel()
                model.insertRow(idx.row(), QtCore.QModelIndex())
</code></pre>

<p>Unfortunately i get the following error:</p>

<pre><code>model.insertRow(idx.row(), QtCore.QModelIndex())
AttributeError: 'PySide.QtGui.QItemSelectionModel' object has no attribute 'insertRow'
</code></pre>

<p>Untested, but try holding a reference to your model<br>
then call the appropriate methods of the model (insertRow, insertColumn).<br>
The effect of these methods will be apparent in the view.
E.g.:</p>

<pre><code>table_view = QtGui.QTableView()
table_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
table_view.setSelectionBehavior( QtGui.QTableView.SelectItems )
model = QtGui.QStandardItemModel(4, 2)
table_view.setModel(model)
model.insertRow(2, QtCore.QModelIndex())
</code></pre>

python qt pyside