Python Forum

Full Version: Pyqt5: How do you make a button that adds new row with data to a Qtablewidget
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
It depends on how many columns a row has and in which column it should be inserted.
(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.
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.
(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.
I have an Example on github that loads tab delimited csv into QTableWidget.

Maybe this helps you.
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.