Python Forum
[PyQt] Pyqt5: How do you make a button that adds new row with data to a Qtablewidget - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [PyQt] Pyqt5: How do you make a button that adds new row with data to a Qtablewidget (/thread-23456.html)



Pyqt5: How do you make a button that adds new row with data to a Qtablewidget - YoshikageKira - Dec-31-2019

My goal is to create a view only table that allows you to add data to table that is then displayed.

Im having trouble with making a script that will actually add a new row to the current amount of rows. Im also having trouble trying to display the data in advance.

Think of it like a program that has a line edit that allows you input whatever into it, then afterwards have a button that displays it on a table.

Thanks in advance!


RE: Pyqt5: How do you make a button that adds new row with data to a Qtablewidget - Axel_Erfurt - Dec-31-2019

It depends on how many columns a row has and in which column it should be inserted.


RE: Pyqt5: How do you make a button that adds new row with data to a Qtablewidget - YoshikageKira - Dec-31-2019

(Dec-31-2019, 09:27 AM)Axel_Erfurt Wrote: It depends on how many columns a row has and in which column it should be inserted.

Each column has 3 rows and every column will be filled in each row.


RE: Pyqt5: How do you make a button that adds new row with data to a Qtablewidget - Denni - Dec-31-2019

Okay first you are approaching this in the wrong manner... the data in a QTreeView or QTreeWidget should be stored within your code within a List or Dictionary and any and all manipulation you are doing to the data occurs to this in code List/Dictionary -- then whenever you want you simply update the QTreeView/QTreeWidget with your data.

Either that or you let them add a row to the QTreeView and edit its contents directly but either way the behind the scenes functionality is taking place within your List/Dictionary -- you are just implementing the Editing slightly differently is all.


RE: Pyqt5: How do you make a button that adds new row with data to a Qtablewidget - YoshikageKira - Jan-01-2020

(Dec-31-2019, 10:19 PM)Denni Wrote: Okay first you are approaching this in the wrong manner... the data in a QTreeView or QTreeWidget should be stored within your code within a List or Dictionary and any and all manipulation you are doing to the data occurs to this in code List/Dictionary -- then whenever you want you simply update the QTreeView/QTreeWidget with your data.

Either that or you let them add a row to the QTreeView and edit its contents directly but either way the behind the scenes functionality is taking place within your List/Dictionary -- you are just implementing the Editing slightly differently is all.

I understand that but my problem is I don't how to script the data into the QTablewidget because it doesn't display at all if I do so.


RE: Pyqt5: How do you make a button that adds new row with data to a Qtablewidget - Axel_Erfurt - Jan-01-2020

I have an Example on github that loads tab delimited csv into QTableWidget.

Maybe this helps you.


RE: Pyqt5: How do you make a button that adds new row with data to a Qtablewidget - Denni - Jan-02-2020

YoshikageKira Wrote:I understand that but my problem is I don't how to script the data into the QTablewidget because it doesn't display at all if I do so.

Okay you need to clarify this -- what do you mean by "script the data into the QTableWidget" what is it that you are trying to do exactly that you are not able to do -- have you created a MUC (Minimal Usable Code) to experiment with this and if no -- then can you provide a MRE (Minimal Reproducible Example) that shows what you are doing that is not working for you. Either of these two a MUC or MRE posted here will get you a much more efficient as well as quicker answer.