How can i fill qtablewidget(pyqt5) with mongodb datas

i need some help to populate the table with mondodb datas. My query brings to me just keys. where am i doing wrong? please someone help me

There’s not enough information here to help further.

What’s the query you’re performing and how are you performing it? Please provide as much detail as possible otherwise it would make it difficult to assist.

BR,
Jason

def loaddata(self):

    self.table.setColumnCount(self.numcolumn)
    self.table.setRowCount(self.numrow)
    self.table.setColumnHidden(0,True)
    self.table.setHorizontalHeaderLabels(self.baslik)

    for i in reversed (range(self.table.rowCount())):
        self.table.removeRow(i)

    db = client['kisiler']
    self.collection = db['muvekkiller']
    self.data = self.collection.find()


    girecekler=self.collection.find_one()
    print(girecekler.keys)




    self.table.setRowCount(0)
    for row_number, row_data in enumerate(self.data):
        self.table.insertRow(row_number)

        for column_number, data in enumerate(row_data):
            self.table.setItem(row_number, column_number, QTableWidgetItem(str(data)))

Actually I solved this problem with pandas data fame. but it made no sense to me.

Glad to hear Orhan.

Perhaps it may have been more so to do with presenting the data rather than querying it although just a thought.

You could include any changes made here so that someone could explain but if you believe it was unrelated to MongoDB then perhaps maybe stack overflow would work too.

Regards,
Jason

def loaddata(self):

    self.table.setColumnCount(self.numcolumn)
    self.table.setRowCount(self.numrow)
    self.table.setColumnHidden(0, True)


    for i in range(self.table.rowCount()):
        self.table.removeRow(i)

    db = client['kisiler']
    collection = db['muvekkiller']
    ducuments = collection.find()
    list_cur=list(ducuments)
    df=DataFrame(list_cur)
    #print(df)

    nRows,nColumns=df.shape
    self.table.setColumnCount(nColumns)
    self.table.setRowCount(nRows)

    self.table.setHorizontalHeaderLabels(df.head())
    for i in range(self.table.rowCount()):
        for j in range(self.table.columnCount()):
            self.table.setItem(i,j,QTableWidgetItem(str(df.iloc[i,j])))
1 Like

this is my solution. I loaded data into table with pandas dataframe

1 Like

Thank you for uploading that solution for others to view in future :slightly_smiling_face:

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.