Results 1 to 4 of 4

Thread: Save TreeWidget into XML-FIle

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jul 2015
    Location
    Austria
    Posts
    20
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    3

    Default Re: Save TreeWidget into XML-FIle

    Yes the value is in the 2nd column. The description is in the 1st column. And the Problem is that i only get the desc in the XML-File because it´s a QString .

    I call the Function with this code

    Qt Code:
    1. writeXml("D:/file.txt",parentTreeWidget);
    To copy to clipboard, switch view to plain text mode 

    I get this Output: (attribute=description and the cell will be a id of a TableWidget-Cell).


    <?xml version="1.0" encoding="UTF-8"?>
    <cell>
    <attribute ="">
    <attribute ="Path">
    <value> </value>
    </attribute>
    <attribute ="Find Images">
    <value> </value>
    </attribute>
    <attribute ="Duration">
    <value> </value>
    </attribute>
    <attribute ="Visibility">
    <value> </value>
    </attribute>
    <attribute ="strech Images">
    <value> </value>
    </attribute>
    </attribute>
    </cell>
    It ignores the Top-Level <attribute=""> also. (because it´s a QLineEdit)
    when the user input is this:
    Unbenannt.PNG

    I create the treewidget-entries with this custom method:

    Qt Code:
    1. void ImageModul::addTreeEntry(QString headerItemString,QStringList itemNameString,QWidget *widgets[],int arrayLenght)
    2. {
    3. QFont font("Helvetica ", 10, QFont::Bold);
    4. QLineEdit *nameLineEdit = new QLineEdit();
    5. nameLineEdit->setStyleSheet("QLineEdit { qproperty-frame: false }");
    6. nameLineEdit->setText(headerItemString);
    7. nameLineEdit->setFont(font);
    8. QTreeWidgetItem *HeaderItem = new QTreeWidgetItem(parentTreeWidget);
    9. parentTreeWidget->setItemWidget(HeaderItem,0,nameLineEdit);
    10. HeaderItem->setFirstColumnSpanned(true);
    11.  
    12. for(int i=0;i<arrayLenght;i++)
    13. {
    14. QTreeWidgetItem *treeItem = new QTreeWidgetItem(HeaderItem);
    15. treeItem->setText(0,itemNameString.at(i));
    16. treeItem->setText(1," ");
    17. parentTreeWidget->setItemWidget(treeItem,1,widgets[i]);
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 


    And in the contructor
    Qt Code:
    1. ImageModul::ImageModul(BaseWidget *parent,QTreeWidget *p) :
    2. BaseWidget(parent)
    3. {
    4. parentTreeWidget=p;
    5. imageName=new QLineEdit();
    6. imagePath=new QLineEdit();
    7. imageTime=new QSpinBox();
    8. imageVisible=new QCheckBox();
    9. imageStrech=new QCheckBox();
    10. imageDirectory=new QPushButton("search...");
    11.  
    12.  
    13. rows<<"Path"<<"Find Images"<<"Duration"<<"Visibility"
    14. <<"strech Images";
    15. QWidget *w[5]= {imagePath,imageDirectory,imageTime,imageVisible,imageStrech};
    16. addTreeEntry("Images",rows,w,5);
    To copy to clipboard, switch view to plain text mode 
    Last edited by mayrhofer; 27th December 2015 at 13:30.

Similar Threads

  1. How to save a file in UTF with BOM?
    By Alan_K in forum Newbie
    Replies: 6
    Last Post: 19th March 2011, 22:32
  2. Replies: 2
    Last Post: 18th May 2010, 23:44
  3. Save File in another Folder
    By GonzoFist in forum General Programming
    Replies: 14
    Last Post: 20th April 2010, 13:59
  4. Save file dialog
    By yxtx1984 in forum Newbie
    Replies: 1
    Last Post: 22nd January 2010, 12:00
  5. Replies: 1
    Last Post: 28th July 2009, 07:58

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
  •  
Qt is a trademark of The Qt Company.