The code of my table is:
from PyQt5 import QtCore
from PyQt5 import QtWidgets
from PyQt5 import QtGui
import configparser
import os
from util.excelUtil import *
class Tabla(QWidget):
'''
Metodo base para la creación de una tabla con el botón de exportación a excel
'''
def __init__(self, contenidoTabla, *args, **kwargs):
super().__init__(*args, **kwargs)
#Boton de exportar a excel
self.toolButton = QtWidgets.QToolButton()
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap(os.getcwd()+"\images\excel_tras.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.toolButton.setIcon(icon1)
self.toolButton.setObjectName("toolButton")
self.toolButton.clicked.connect(lambda i: exportar(contenidoTabla))
#Tabla
contenidoTabla.table = QtWidgets.QTableView()
contenidoTabla.table.setObjectName("table")
contenidoTabla.tableWidget = QtWidgets.QTableWidget()
contenidoTabla.tableWidget.setObjectName("tableWidget")
contenidoTabla.tableWidget.setColumnCount(len(contenidoTabla.columnas))
contenidoTabla.tableWidget.setRowCount(len(contenidoTabla.listaDatos))
contenidoTabla.tableWidget.setSortingEnabled(True)
#Definir los eventos de la tabla
contenidoTabla.tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
contenidoTabla.tableWidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
contenidoTabla.tableWidget.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
#Colocamos la cabecera
contenidoTabla.tableWidget.setHorizontalHeaderLabels(contenidoTabla.columnas)
header_view = contenidoTabla.tableWidget.horizontalHeader()
header_view.setSectionResizeMode(QtWidgets.QHeaderView.ResizeToContents)
#Layout
contenidoTabla.mainLayout.addWidget(contenidoTabla.tableWidget, 7, 0, 5, 7)
contenidoTabla.mainLayout.addWidget(self.toolButton, 6, 6, 1, 1, QtCore.Qt.AlignRight)
#Evento
#contenidoTabla.tableWidget.doubleClicked.connect(self.on_click)
contenidoTabla.tableWidget.cellClicked.connect(self.on_click)
#Metodo asociado al evento de hacer doble click sobre una fila de la tabla
#@QtCore.pyqtSlot(QtCore.QModelIndex)
def on_click(self, row, column):
print("Row %d and Column %d was clicked" % (row, column))
item = self.table.itemAt(row, column)
self.ID = item.text()
And I create it from my window as:
def crearTabla(self):
Tabla(self)
My problem is that when I run the program and select a row, the event does not fire.