Results 1 to 2 of 2

Thread: Printer paper layouts

  1. #1
    Join Date
    Nov 2009
    Location
    Finland
    Posts
    12
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Printer paper layouts

    I have a BIG problem. i am making billing program and i need print my invoices, i can print my invoices yes but i cant find a way to make good layout/template for it. in my country the invoices is strandard and i have to use that template.

    here is the code :
    Qt Code:
    1. QString html;
    2. QString css;
    3.  
    4.  
    5. css +=".padding5px{padding:5px 5px 5px 5px; border-color:white}";
    6. css +=".padding10px{padding:5px 5px 5px 5px; border-color:white}";
    7. css +=".t{background-color:blue;border:1px solid black;}";
    8.  
    9. html +="<html>";
    10. html+="<head><link rel='stylesheet' type='text/css' href='testi.css'></head>";
    11. html +="<body><table class='t' width='100%' border=0 cellspacing=0>"
    12. "<tr><td><font size='+1'>"
    13. "<b><i>" + title +"</i></b></font></td>";
    14. html+="<td>Päivämäärä <br> 30.6.2010 </td>";
    15. html+="<td>Laskunnumero 15555</td>";
    16. html+="<tr><td rowspan='4' style='border:1px black solid;'>"+asiakkaanLaskutusnimi+"<br>";
    17. html+=asiakkaanLaskutusosoite+"<br>"+asiakkaanLaskutusPostinro+" "+asiakkaanLaskutusPostitoimi;"</td>";
    18. html+="<td>Viitteenne</td><td>Viitteenne</td><tr>";
    19. html+="<td>Asiakasnro</td><tr><td>Toimitusaika</td>";
    20. html+="<td>Huomautusaika</td><tr><td>Maksuehto</td><td>viivästyskorko</td></table><br><br>";
    21. html+="<table border=0 cellspacing='3'><tr >";
    22. html+="<td>Tuotenumero</td><td>Tuotenimi</td><td>kpl-hinta</td><td>Alennus</td><td>Yhteensä</td><tr>";
    23.  
    24. for(int i=0; i<=m_ui->tuotteetTable->rowCount()-1;i++){
    25. QTableWidgetItem *tuotenro = m_ui->tuotteetTable->item(i,0);
    26. QTableWidgetItem *tuoteNimi = m_ui->tuotteetTable->item(i,1);
    27. QTableWidgetItem *tuoteKplhinta = m_ui->tuotteetTable->item(i,2);
    28. QTableWidgetItem *tuoteRivihinta = m_ui->tuotteetTable->item(i,3);
    29. QTableWidgetItem *alennus = m_ui->tuotteetTable->item(i,4);
    30.  
    31. html+="<td ><font size='+1'>"+tuotenro->text()+"</font></td><td><font size='+1'>"+tuoteNimi->text()+"</font></td><td><font size='+1'>"+tuoteKplhinta->text()+"</font></td><td><font size='+1'>"+alennus->text()+"</font></td><td><font size='+1'>"+tuoteRivihinta->text()+"</font></td><tr>";
    32. }
    33. html+="</table><br>";
    34. html+="<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr>";
    35. html+="<td width='20' class='padding5px' align='right'><font size='-1' >Saajan tilinumero<br> Mottagarens kontonummer</font></td><td width='300' height='50'>EKSP xxxxxx-xxxxxx</td>";
    36. html+="<td colspan='3' height='50'><font size='-1'>IBAN</font></td><td colspan='2' ><font size='-1'>BIC</font></td><tr>";
    37. html+="<td width='20' class='padding5px' align='right'><font size='-1'>Saaja<br>Mottagare</font></td><td class='padding10px' width='200'>Testi Yrityks KY</td>";
    38. html+="<td colspan='5' rowspan='2'></td><tr>";
    39. html+="<td width='20' class='padding5px' align='right'><font size='-1' >Maksajan nimi ja osoite<br>Betalaren namn och adress</font></td><td class='padding10px'>"+asiakkaanLaskutusnimi+"<br>"+asiakkaanLaskutusosoite+"<br>"+asiakkaanLaskutusPostinro+" "+asiakkaanLaskutusPostitoimi+"</td>";
    40. html+="<tr><td width='20' class='padding5px' align='right'><font size='-1' >Allekirjoitus<br>Underskrift</font></td><td>----------------------------------------</td>";
    41. html+="<td class='padding5px' align='left'><font size='-1' >Viitenro<br> ref.nr</font></td><td colspan='4'></td><tr>";
    42. html+="<td width='20' class='padding5px' align='right'><font size='-1' >Tililtä nro.<br> Från konto nr</font></td><td width='50'></td><td width='20'><font size='-1'>Eräpäivä<br>Förf.dag</font></td><td width='100' colspan='2'>xx.xx.xxxx</td><td colspan='2'><b>EUR</b></td></table>";
    43.  
    44.  
    45. html +="</table><br></body></html>";
    46.  
    47.  
    48.  
    49. QPrinter printer(QPrinter::ScreenResolution);
    50.  
    51. printer.setPrinterName("HP LaserJet 4100 Series PCL6");
    52. printer.setPaperSize(QPrinter::A4);
    53. printer.setDocName("Testi");
    54. printer.setOrientation(QPrinter::Portrait);
    55. printer.setOutputFormat(QPrinter::PdfFormat);
    56. printer.setOutputFileName("lasku.pdf");
    57. printer.setFullPage(true);
    58. printer.setNumCopies(1);
    59. printer.setResolution(300);
    60. QTextDocument *document = new QTextDocument;
    61.  
    62. document->addResource(QTextDocument::StyleSheetResource,QUrl("testi.css"),css);
    63. document->setHtml(html);
    64. document->print(&printer);
    To copy to clipboard, switch view to plain text mode 

    And the problem is that when i use css styles border attribute the qt richtext engine doesent support it so. is there any other way to do this where i can edit the table data borders, XML mayby ?
    the only solution what i came up with is that i make widget for this and print that but this doesent sound right to me. I have googled but i cant find any solution for this. So if any one have a good tutorial or solution for this please tell me, And the Qt version is 4.6 opensource

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Printer paper layouts

    Hi,

    the template doesn't look so complicated, so you can do all the painting yourself using QPainter. Draw the text and lines (= border) with the common functions.


    Lykurg

Similar Threads

  1. Is it possible to create a combo with paper sizes?
    By aekilic in forum Qt Programming
    Replies: 10
    Last Post: 19th January 2010, 09:16
  2. TSP problem paper
    By mickey in forum General Discussion
    Replies: 3
    Last Post: 5th May 2009, 16:50
  3. Replies: 0
    Last Post: 26th October 2008, 13:56
  4. How I setup QPrinter paper margins
    By vcp in forum Qt Programming
    Replies: 3
    Last Post: 15th May 2008, 17:43
  5. Printing and Paper Geometry
    By croftj in forum Qt Programming
    Replies: 5
    Last Post: 19th December 2007, 21:29

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.