I am a beginner of PyQGIS and I'm trying to do a QGIS plugin, with QGIS 3.4.7 and PyCharm 2016.3.6. I already did the "dialog" box on Qt and after I wrote on Pycharm. It is a table only with the columns that I want.
I have the CSV file and my code. But when read the file directly on code and trying to write the iteraccion, it's kinda missing something, it means, the variable that belongs to the class QTableWidget
(called tbwidget_data_list_service
) on the code doesn't show up with .setItem
(function and property of QTableWidget
class). I have all libraries imported (PyQt5, and others), so I don't understand that's wrong.
I have some commented code 'cause I had many attempts to try this working...
Can someone tell me what's wrong or give another example?
Here's the code:
class DataListService(FrameworkSupportConsumer):
def __init__(self, framework_support):
super(DataListService, self).__init__()
self.set_framework_support(framework_support)
# Set QAction
icon_path = ":/plugins/marineo_ocean/service_management.png"
icon_action = QIcon(icon_path)
message_action = 'Data List Service'
self.action_data_list_service = QAction(icon_action, message_action, self.iface.mainWindow())
# Get and register dialog
self.dlg = DataListServiceDialog(self.iface.mainWindow())
self.register_dialog('data list service', self.dlg)
# ler csv
dadosaimportar = []
ruta = "C:/Users/gviana/Desktop/MARINEO_PHASE_1/marineo_1/qgis/profiles/default/python/plugins/marineo_ocean/request.txt"
reader = csv.reader(open(ruta), delimiter=';')
for row in reader:
dadosaimportar.append(row)
numLinhas = len(dadosaimportar)
numColunas = 7
# self.tbwidget_data_list_service = QtWidgets.QTableWidget()
#self.dlg.tbwidget_data_list_service.setRowCount(numLinhas)
#self.dlg.tbwidget_data_list_service.setColumnCount(numColunas)
for linha, umaLinha in enumerate(dadosaimportar):
for coluna, value in enumerate(umaLinha):
item = QtWidgets.QTableWidgetItem()
item.setText(self,value)
self.dlg.tbwidget_data_list_service.setItem(linha, coluna, item)
# Connect events
self.connect_signals()
def unload(self):
pass
def connect_signals(self):
self.action_data_list_service.triggered.connect(self.show_dialog)
self.dlg.pushbtn_close_service.clicked.connect(self.close_dialog)
def download_data(self):
pass
def display_data(self):
pass
def close_dialog(self):
self.dlg.close()
def show_dialog(self):
self.dlg.show()