1 Attachment(s)
Updation of QTableWidget from xml file in Pyside2
I am trying to populate data into a QTableWidget , but i am facing difficulty in the logic for populating corresponding rows and columns of the table.
I have the input coming from xml document and I want the rows to increase dynamically according to the data present in the xml file.
<Message>'120' <break> Statement</break> w_addr <= (others => '0');</Message>
<Message>'136' <break> Statement </break>r_addr <= (others => '0');</Message>
I want the data to be captured from the <Message> tag and populated on QTableWidget as shown in the image.The rows should increase dynamically according to number of <Message> elements
Attachment 13556
Re: Updation of QTableWidget from xml file in Pyside2
So what have you tried?
My suggestion would be to first separate the action of reading the XML file from the action of adding information to a table. Use a data structure to hold the information as you read it from the file (a Python list of lists would work, where each item in the inner list is a column and each of the outer list is a row).
If your XML format is as simple as what you have displayed, then you can probably parse it by hand, looking for <Message> elements and then pulling out each piece and adding it to a column list until you reach the </Message> closing element. You then stick that column list onto the end of your row list. If your XML is more complex or the items in each message are not the same or in the same order, then you can use QDomDocument to read it in and then search for and pull out each <Message> element to retrieve its attributes and data.
After you have completely read your message file, then you build your table. First set the total number of rows and columns according to your list (QTableWidget::setRowCount(), QTableWidget::setColumnCount()). Then go through your list of lists, adding QTableWidgetItem instances for each column in the inner lists, row by row: QTableWidget::setItem().
Re: Updation of QTableWidget from xml file in Pyside2
Thanks for your help . I followed this approach and was able to achieve that i needed.