Results 1 to 2 of 2

Thread: How to show table from QTableWidget in txt file?

  1. #1
    Join Date
    Jun 2019
    Posts
    6
    Thanks
    1
    Qt products
    Qt5

    Default How to show table from QTableWidget in txt file?

    Hi,
    I am trying to extract all items of my table and stream to txt file.
    This is what I have done
    Qt Code:
    1. QFile file("/home/ramraj/Desktop/bill.txt");
    2. if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
    3. qDebug()<<"file not open";
    4.  
    5. QTextStream out(&file);
    6. QString companyName=ui->companyName->text();
    7. QString companyAddress=ui->addressLabel_2->text();
    8. QString companyPhone=ui->phoneLabel_2->text();
    9. QString companyEmail=ui->emailLabel_2->text();
    10. QString companyVAT=ui->vatLabel_2->text();
    11.  
    12. out <<" "<<companyName<<endl;
    13. out <<" "<<companyAddress<<endl;
    14. out <<" "<<companyPhone<<","<<companyEmail<<endl;
    15. out <<" "<<"VAT No.:"<<companyVAT<<endl;
    16. out <<" "<<"ABBREVIATED TAX INVOICE"<<endl;
    17. out <<endl<<endl;
    18. out <<"Bill # :"<<endl;
    19. out <<"Date :"<<ui->currentDate->text()<<endl;
    20. out<<"Payment Mode: Cash"<<endl;
    21. out <<"-----------------------------------------------------------------------------------------------------------"<<endl;
    22. out <<"ID\t" <<"Particulars\t\t\t"<<"Rate\t\t"<<"Quantity\t"<<"Amount"<<endl;
    23. out <<"-----------------------------------------------------------------------------------------------------------"<<endl;
    24. QString textData;
    25. int rows = ui->billTable->rowCount();
    26. int columns = ui->billTable->columnCount();
    27. for (int i = 0; i < rows; i++) {
    28. for (int j = 0; j < columns; j++) {
    29.  
    30. textData += ui->billTable->item(i,j)->text();
    31. textData += "\t\t";
    32. }
    33. textData += "\n";
    34.  
    35. }
    36. out<<textData<<endl;
    37. out<<"---------------------------------------------------------------------------------------------------------------"<<endl;
    38. out<<" "<<"Total:"<<ui->subTotal_2->text()<<endl;
    To copy to clipboard, switch view to plain text mode 


    But,I am unable to get good alignment.
    Here is what I have got:
    Screenshot from 2019-07-16 09-53-32.jpg
    Please,could anyone solve it?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to show table from QTableWidget in txt file?


Similar Threads

  1. Centering a table in QTableWidget
    By Malorn44 in forum Newbie
    Replies: 1
    Last Post: 4th April 2019, 08:21
  2. Replies: 1
    Last Post: 20th January 2015, 18:49
  3. show the images in table column
    By Sara9 in forum Qt Programming
    Replies: 1
    Last Post: 2nd September 2011, 11:39
  4. QTableWidget resizeColumnsToContents for whole table?
    By lalesculiviu in forum Qt Programming
    Replies: 1
    Last Post: 2nd March 2010, 01:08
  5. Replies: 4
    Last Post: 4th February 2008, 07:16

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.