0
我想使用工具箱構建多個文檔報告。兩頁是一個選項開始。格式化是好的,可以用後者來工作。Qt Python - 工具箱中的報告:QTextDocument和QPainter
我試過在Html中使用QTextDocument,或者是QPainter。
當然,要進行測試並保持簡單,我只需要在Qt中顯示在文檔頂部顯示的報告標題。
這裏是工具箱主框架的功能:
def toolbox_frame(self,MainWindow):
self.toolBox = QtGui.QToolBox(self.centralwidget)
self.toolBox.setGeometry(QtCore.QRect(10, 20, 471, 201))
self.toolbox_page1()
self.toolBox.addItem(self.page1, "")
self.toolBox.setItemText(self.toolBox.indexOf(self.page1), QtGui.QApplication.translate("MainWindow", "Page 1", None, QtGui.QApplication.UnicodeUTF8))
self.toolbox_page2()
self.toolBox.addItem(self.page2, "")
self.toolBox.setItemText(self.toolBox.indexOf(self.page2), QtGui.QApplication.translate("MainWindow", "Page 2", None, QtGui.QApplication.UnicodeUTF8))
...保存使用另外,QTextDocument使用HTML第一頁的功能:
def toolbox_page1(self):
self.page1 = QtGui.QWidget()
self.page1.setGeometry(QtCore.QRect(0, 0, 471, 145))
html = u""
html += (" <p><font color=red><b>Title - Build "
"a Report : page 1.</b></font>")
document = QtGui.QTextDocument(self.page1)
document.setHtml(html)
這裏使用QPainter的功能:
def toolbox_page2(self):
self.page2 = QtGui.QWidget()
self.page2.setGeometry(QtCore.QRect(0, 0, 471, 145))
sansFont = QtGui.QFont("Helvetica", 10)
painter = QtGui.QPainter(self.page2)
painter.setFont(sansFont)
painter.setPen(QtGui.QColor(168, 34, 3))
x=50
y=50
painter.drawText(x, y, "Title - Build a Report : page 2")
問題是,它只是顯示帶有頁面1和頁面的工具箱2,但不是頁面1和頁面2中報告的標題。
這裏缺少什麼?
所有的意見和建議,非常感謝。
感謝BaySmith!你剛剛救了一天。它只是工作得很漂亮! – ThreaderSlash 2010-01-01 23:49:16