Results 1 to 3 of 3

Thread: Updation of QTableWidget from xml file in Pyside2

  1. #1
    Join Date
    Aug 2019
    Posts
    15
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default 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 &lt;= (others =&gt; '0');</Message>

    <Message>'136' <break> Statement </break>r_addr &lt;= (others =&gt; '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
    qtforum.PNG

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default 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().
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    supratik (13th October 2020)

  4. #3
    Join Date
    Aug 2019
    Posts
    15
    Thanks
    6
    Qt products
    Qt5
    Platforms
    Windows

    Default 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.

Similar Threads

  1. Replies: 3
    Last Post: 10th March 2020, 05:18
  2. Replies: 5
    Last Post: 20th February 2020, 21:28
  3. QTableWidget does not allow updation of a cell
    By karankumar1609 in forum Qt Programming
    Replies: 0
    Last Post: 29th July 2013, 12:03
  4. Fast updation for controls in QT3
    By soumyadeep_pan in forum Qt Programming
    Replies: 18
    Last Post: 30th September 2008, 06:02
  5. Inactive window Updation
    By csvivek in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2008, 09:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.