Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to send bunch of strings to printer?
Forum Updated to NodeBB v4.3 + New Features

How to send bunch of strings to printer?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ivica
    wrote on last edited by
    #1

    Hello everyone,

    my application is coming up nicely, with all the problems I've asked help for it better be :) Last thing I wanted to make is the ability to print (or make a report) various strings queried from database. I googled a lot, found ReportLab Toolkit, reStructuredText and more, but that is not what I am looking for.

    Here is my code:

    @def preparePrint(self):
    caseNumber = (str(self.ui.linecaseNumber.text()).upper())
    if caseNumber:
    with con:
    cur = con.cursor()
    cur.execute('SELECT notes FROM cases WHERE caseNumber =?',[caseNumber])
    tempnotes=str(cur.fetchone())
    cur.execute('SELECT name FROM cases WHERE caseNumber =?',[caseNumber])
    tempname=str(cur.fetchone())
    cur.execute('SELECT date FROM cases WHERE caseNumber =?',[caseNumber])
    tempdate = str(cur.fetchone()) #fetch 3 values from SQLite database

    tempname = (str(tempname.replace('(','').replace(')','').replace(',','').replace("'","")))
    tempnotes = (str(tempnotes.replace('(','').replace(')','').replace(',','').replace("'","")))
    tempdate=(str(tempdate.replace('(','').replace(')','').replace(',','').replace("'",""))) #get rid of "tuple marks"

    finalText = (str("NAME: %s\nDATE: %s\nNOTES: %s" %(tempname,tempdate,tempnotes))) #join them in one string. Notice the \n
    self.ui.textPrint.setHtml(str(finalText.replace('(','').replace(')','').replace(',','').replace("'","").replace('\n','\r'))) #put the joined string into one QTextEdit, while preserving HTML properties (bold mostly).@

    After this function, there is one for creating PDF which works EXCEPT newline characters. When I print finalText to console it looks the way I want it to. It does not look like that in QTextEdit :(

    Console output:
    @
    Name: Some Name
    Date: 14.07.2012
    Notes: Some notes go here@

    QTextEdit output:

    @
    Name: Some Name Date: 14.07.2012 Notes: Some notes go here@

    It IGNORES replacement of \n with \r . Same replace works nicely in another QTextEdit. Am I doing something wrong?

    1 Reply Last reply
    0
    • I Offline
      I Offline
      ivica
      wrote on last edited by
      #2

      I cracked it! :D

      Since QTextEdit accepts HTML, <br> tag will make a newline. Here is a piece of code that is different from original post.

      @finalText = (str("NAME: %s%sDATE: %s%sNOTES: %s%s" %(tempname,'<br>',tempdate,'<br>',tempnotes,'<br>')))

      self.ui.textPrint.setHtml(str(finalText).replace('\n','\r'))@

      Might not be convenient for larger pieces of text, but one A4 page (which is my aim) won't be a problem.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved