Results 1 to 4 of 4

Thread: Qtableview xml

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2020
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Qtableview xml

    im trying to parse data from a qtableview to xml here is my code below:

    Qt Code:
    1. #
    2. table = self.the_material_view.the_model
    3. row = table.item
    4. input_1 = table.item(row,0).text().strip()
    5. input_2 = table.item(row,1).text().strip()
    6. input_3 = table.item(row,2).text().strip()
    7. filename = QFileDialog.getSaveFileName(self, self.tr('Save File'),
    8. os.getcwd(), self.tr("xml files (*.xml);; All files(.txt)"))
    9. file = open(filename[0],"w")
    10. file.write('<name>{name}</name>\n'.format(name=input_1))
    11. file.write('<material_type>{material_type}</material_type>\n'.format(material_type=input_2))
    12. file.write('<density>{density}</density>\n'.format(density=input_3))
    13. for row in range(3):
    14. for column in range(3):
    15. if table.cellWidget(row, column) == True:
    16. file.write('<c{row}{col}>{data}</c{row}{col}>\n'.format(row=row + 1, col=column + 1,
    17. data=table.item(row, column).text().strip()) + "\n")
    To copy to clipboard, switch view to plain text mode 

    i tried using currentIndex function but keep getting an error, the tableview is not callable, the model is based on QtGui.QStandardItemModel()
    Last edited by d_stranz; 2nd March 2021 at 01:04. Reason: missing [code] tags

Similar Threads

  1. Replies: 2
    Last Post: 9th December 2015, 02:07
  2. set XML tag to QTableView
    By mythili in forum Qt Programming
    Replies: 10
    Last Post: 7th May 2013, 13:43
  3. QTableView and QLineEdit OUTSIDE of QTableView, like Excel
    By JoZCaVaLLo in forum Qt Programming
    Replies: 10
    Last Post: 13th May 2011, 14:20
  4. Replies: 2
    Last Post: 26th November 2009, 05:45
  5. QTableView help
    By weaver4 in forum Qt Programming
    Replies: 4
    Last Post: 24th November 2009, 23:57

Tags for this Thread

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.