python - Converting a QTreeWidge in PyQt to a Table in ReportLab -
python - Converting a QTreeWidge in PyQt to a Table in ReportLab -
as tables seem overly complicated in reportlab, i'm trying determine means add together (preferably through paragraph class, if possible) 2 separate texts, 1 on left side of page , other on right. much net find no seeming explanation of how accomplish this. if possible, how do it?
at end i'm trying pull off converting info qtreewidget in pyqt pdf similar , feel.
thanks in advance!
it appear accomplishing best done through tables. though convoluted, learning construction of table info nested lists way go. key converting qtreewidget info goes along lines of codes below, in have dynamically append both info , cell styling work way through table data.
assuming qtreewidget's composition items 2 columns of text (0, , 1), below works.
from reportlab.lib.units import inch reportlab.lib.pagesizes import letter reportlab.platypus import simpledoctemplate, table, tablestyle pdf = simpledoctemplate("treewidgetpdf.pdf", pagesize = letter) info = [] tstyle = [] x in qtreewidgetdata.finditems("*", qt.matchwildcard, 0): project = str(x.text(0)) data.append([project, x.text(1)]) tstyle.append(('background', (0, cell), (1, cell), 'yellow')) tstyle.append(('fontsize', (0, cell), (1, cell), 12)) cell+=1 y in range(x.childcount()): data.append([str(x.child(y).text(0)), str(x.child(y).text(1))]) tstyle.append(('align', (1, cell), (1, cell), 'right')) tstyle.append(('leftpadding', (0, cell), (0, cell), 15)) cell+=1 z in range(x.child(y).childcount()): data.append([x.child(y).child(z).text(0), x.child(y).child(z).text(1)]) tstyle.append(('align', (1, cell), (1, cell), 'right')) tstyle.append(('leftpadding', (0, cell), (0, cell), 30)) cell+=1 # , on , forth. iterate through in # while loop don't have manually nest statements. parts = [] styledtable = table(data, [6 * inch, 1 * inch, 0]) styledtable.setstyle(tablestyle(tstyle)) parts.append(table_with_style) pdf.build(parts)
python formatting reportlab
Comments
Post a Comment