Signal Slot Connections QItemDelegate -- QPushButton Editor Clicked Signal with Model Class ( QAbstractTableModel )Slot

I am trying to connect my Delegate Class

class Delegate(QItemDelegate):


   def createEditor(self, parent, option, index):
        if index.column()==1:
            self.btn=QPushButton(parent)
            self.button.clicked.connect(self.Model.rowOp(int,int,QModelIndex()))
            return self.lineedit

QPushButton clicked Signal to QAbstractTableModel Class Slot, which take 3 arguments(int,int,QModelIndex).

Please suggest with a working example

I have tweaked it little bit, Instead of performing Row related operations in Model Class moved the Table row operations to the Delegate class, Where Editor(QPushButton)has the needed scope.

Delegate Class looks like below.


from PyQt6.QtWidgets import QLineEdit, QItemDelegate, QPushButton, QMessageBox
from PyQt6.QtCore import Qt
import pandas as pd


class Delegate(QItemDelegate):
    def __init__(self, dataframe: pd.DataFrame, parent=None):
        QItemDelegate.__init__(self, parent)
        #self.modl = modelView    #Instead of Getting Model Instance here Got the DataFrame to perform needed Operations
        self._dataframe = dataframe
        self.parent = parent

    def createEditor(self, parent, option, index):
        if index.column() == 9:
            self.lineedit = QLineEdit(parent)
            return self.lineedit

        elif index.column() == 10:
            self.button = QPushButton(parent)
            self.button.clicked.connect(self.showDialog)
            return self.button

    def setEditorData(self, editor, index):
        self.row = index.row()
        self.column = index.column()
        value = index.data()
        value = index.model().data(index, Qt.ItemDataRole.EditRole)
        if isinstance(editor, QPushButton):
            editor.setText(value)
        if isinstance(editor, QLineEdit):
            editor.text()

    def setModelData(self, editor, model, index):
        editor.setText(index.data())
        value = index.data()
        model.setData(index, value)
        pass

    def showDialog(self):
        msgBox = QMessageBox()
        msgBox.setIcon(QMessageBox.Icon.Information)

        msgBox.setText("Delete Selected Row?")
        msgBox.setWindowTitle("Delete!!")
        msgBox.setWindowIcon(QIcon('images/del.png'))
        msgBox.setStandardButtons(QMessageBox.StandardButton.Ok | QMessageBox.StandardButton.Cancel)

        returnValue = msgBox.exec()
        if returnValue == QMessageBox.StandardButton.Ok:
            print('OK clicked')
            # perform Row Remove/Update Operations
            self._dataframe.iat[self.row, self.column] = 0.0