我的應用程序很好,我已經問了所有問題,幫助它更好:)我最想做的是能夠打印(或製作報告)各種從數據庫查詢字符串。我搜索了很多,發現了ReportLab Toolkit,reStructuredText等,但這不是我正在尋找的。PyQt:發送多個字符串到打印機
這裏是我的代碼:(縮進可能會稍微偏離,因爲粘貼)
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
#get rid of "tuple marks"
tempname = (str(tempname.replace('(','').replace(')','').replace(',','').replace("'","")))
tempnotes = (str(tempnotes.replace('(','').replace(')','').replace(',','').replace("'","")))
tempdate=(str(tempdate.replace('(','').replace(')','').replace(',','').replace("'","")))
#join them in one string. Notice the \n
finalText = (str("NAME: %s\nDATE: %s\nNOTES: %s" %(tempname,tempdate,tempnotes)))
#put the joined string into one QTextEdit, while preserving HTML properties (bold mostly).
self.ui.textPrint.setHtml(str(finalText.replace('(','').replace(')','').replace(',','').replace("'","").replace('\\n','\r')))
此功能後,有一個用於創建PDF其中工程EXCEPT換行符。當我打印finalText來控制它看起來我想要的方式。它看起來並不像在的QTextEdit :(
控制檯輸出:
Name: Some Name
Date: 14.07.2012
Notes: Some notes go here
的QTextEdit和PDF輸出:
Name: Some Name Date: 14.07.2012 Notes: Some notes go here
嘗試'\ r \的N'而不只是'\ N' – BrtH 2012-07-14 11:03:06
在_finalText_?它也是一樣的,沒有換行符。 – ivica 2012-07-14 11:16:56
爲什麼在最後使用'.replace('\\ n','\ r')'?刪除它,然後重試。 – BrtH 2012-07-14 12:05:08