'How to get widget from a QStandardItemModel

How to get the widget from a 'QStandardItemModel' using known '(row, colum)'.

First, I create the table

# initialize the model
Mymodel = QStandardItemModel(1, 2)
Mytable = QTableView()
Mytable.setModel(Mymodel)

Then I add the Label widget at 'column=1'

# add QLabel
l1 = QLabel()
l1.setText('Peter Alice')
Mytable.setIndexWidget(Mymodel.index(1, 1), l1)

I used the 'Mytable.selectionModel()' to get the selected row to be deleted. But first, I need to grab the 'text' from the 'l1'.

row, column = Mytable.selectionModel().selectedRows().row(), 1
label = Mytable.model().index(row, column).data()    # it gives None
name  = label.text() 

The approach above '.data()' gives None. How can I grab the corresponding label

The task is to Get the text of that widget at index



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source