<span id="result_box" class="" lang="en"><span class="hps">It would be nice</span> <span class="hps">to know</span> <span class="hps">what the</span> <span class="hps">project aims</span> <span class="hps">...</span><br><span class="hps">I have a feeling</span> <span class="hps">...</span> <span class="hps">not a good</span> <span class="hps">idea</span> <span class="hps">to</span> <span class="hps">be</span> <span class="hps">implemented</span> <span class="hps">...</span><br>
<span class="hps">Perhaps</span> <span class="hps">my idea</span> <span class="hps">of your</span> <span class="hps">projects:</span><br><span class="hps">-</span> <span class="hps">Create a</span> <span class="hps">graphic</span> <span class="hps">based</span> <span class="hps atn">text (</span><span>and graphics)</span><br>
<span class="hps">-</span> <span class="hps">This</span> <span class="hps">post</span> <span class="hps">is a</span> <span class="hps alt-edited">image</span><br><span class="hps">- Then</span> <span class="hps">it is</span> <span class="hps">inserted</span> <span class="hps">into</span> <span class="hps">a</span> <span class="hps">qtextedit (insertImage)</span><br>
<span class="hps">-</span> <span class="hps">QDocument</span> <span class="hps">display</span> <span class="hps atn">(</span><span>print</span><span>, printpreview)</span><br><span class="hps">Graphic</span> <span class="hps">image</span> <span class="hps">of the</span> <span class="hps">page numbering</span> <span class="hps">is not yet known</span> <span class="hps">if the</span> <span class="hps">scene</span> <span class="hps">is only</span> <span class="hps">the size</span> <span class="hps">of pages</span><span>, and</span> <span class="hps">includes</span> <span class="hps atn">pre-</span><span class="">specify</span> <span class="hps">the page number</span> <span class="hps">in the picture.</span></span><span id="result_box" class="" lang="en"><span class="hps"><span id="result_box" class="" lang="en"><span class="hps"> Counting</span> <span class="hps">the rows</span> <span class="hps">do not understand why</span> <span class="hps">it is essential</span> <span class="hps">because</span> <span class="hps">it is</span> <span class="hps">actually</span> <span class="hps">image</span></span>... </span></span><br>
<span id="result_box" class="" lang="en"><span class="hps">(I'm not a</span> <span class="hps">professional</span> <span class="hps">but</span> <span class="hps">I'm</span> <span class="hps">learning about</span> <span class="hps">qt(pyside)</span> <span class="hps">development)<br>
<br></span></span><div class="gmail_quote">2012/10/7 Ofek <span dir="ltr"><<a href="mailto:ofek@outlook.com" target="_blank">ofek@outlook.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div link="blue" vlink="purple" lang="EN-US"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Hi,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Thank you for replying so quickly.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I looked at the code, but Iím looking for a way to use the built-in functions in Qt, rather than computing it manually.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">As I canít possibly get a proper pageCount() from QTextEdit† (keeps returning 1) and because it is easier to add multiple QGraphicsTextItem to a scene, I chose to go with the QGraphics approach.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">This is what I have so far:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><a href="http://pastebin.com/jwfH40JP" target="_blank">http://pastebin.com/jwfH40JP</a><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">A few things arenít working right now: I canít seem to set the TextItem flag from the MultiPage class, only through the class itself.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I also canít focus the TextItem with the mouse or navigate with the keyboard.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Also line count doesnít work for lines that are just bigger from the page width (meaning, without \n)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Those are all problems I have for being new to both Python and Qt, and will be solved.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">The real question here is if you believe that this approach is good (using Qtís functions, and the use of QGraphicsTextItem) to get, eventually, a working word processor.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Thanks again<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"><u></u>†<u></u></span></p><p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Zfox Atis [mailto:<a href="mailto:zfoxatis@gmail.com" target="_blank">zfoxatis@gmail.com</a>] <br>
<b>Sent:</b> Saturday, October 06, 2012 01:12 PM<br><b>To:</b> Ofek<br><b>Cc:</b> <a href="mailto:pyside@qt-project.org" target="_blank">pyside@qt-project.org</a><br><b>Subject:</b> Re: [PySide] QGraphicsTextItem<u></u><u></u></span></p>
<div><div class="h5"><p class="MsoNormal"><u></u>†<u></u></p><p class="MsoNormal" style="margin-bottom:12.0pt"><span><span lang="EN">I also</span></span><span lang="EN"> <span>like</span> <span>things</span> <span>trying.</span>(t<span>his works but</span><span> </span><span>is not the</span><span> </span><span>final</span>) <span>Maybe it</span> <span>will give you</span> <span>some ideas</span>:<br>
(<a href="http://pastebin.com/S2mj1ZS2" target="_blank">http://pastebin.com/S2mj1ZS2</a> )<br><br></span>class ReportPage(QFrame):<br>††† ''' report rootclass<br>††††††† create multi-page finance report: dynamic height of the header and footer'''<br>
††† def __init__(self):<br>††††††† super(ReportPage,self).__init__()<br><br>††††††† self.printer=QPrinter()<br>††††††† self.printer.setPaperSize(QPrinter.A4)<br>††††††† self.printer.setPageMargins(40,30,40,10,QPrinter.Point)<br>
††††††† self.rootEditorTextEdit=QTextEdit()† <br>††††††† <br>††††††† self.createReport()<br>††††††† self.reportGui()<br><br>††† def reportGui(self):pass # ...create printpreview widget<br><br>††† def createReport(self):<br>
† <br>††††††† self.doc=self.rootEditorTextEdit.document()<br>††††††† self.doc.setUseDesignMetrics(True)<br>††††††† self.doc.setPageSize(QSizeF(793,1123)) #(A/4)<br>††††††† self.doc.setDocumentMargin(0)<br>††††††† <br>††††††† self.rootTextCursor = QTextCursor(self.doc)<br>
<br>††††††† self.pageBreakTextBlockFormat=QTextBlockFormat()<br>††††††† self.pageBreakTextBlockFormat.setPageBreakPolicy(QTextFormat.PageBreak_AlwaysBefore)<br><br>††††††† # document fragments:<br>††††††† self.firstPageHeader=None<br>
††††††† self.docTitle=None<br>††††††† self.docPrologText=None<br>††††††† self.notFirstPageHeader=None<br>††††††† self.docDetailHeader=None <br>††††††† self.detailitems=[]<br>††††††† self.detailSummary=None<br>††††††† self.docEndText=None<br>
††††††† self.docEndFooter=None<br>††††††† self.pageFooter=None<br>††††††† <br>††††††† self.reportPartDefinition()<br>††††††† self.reportCompilation()<br>††††††† <br>††† def reportPartDefinition(self):pass #child class create to document fragments <br>
†† <br>††††††† <br>††† def reportCompilation(self):<br>††††††† self.max_page_height=self.printer.pageRect().height()-10 # -10 point repair counting<br>††††††† try:<br>††††††††††† self.page_footer_textHeight=self.pageFooter.textHeight() <br>
††††††† except: <br>††††††††††† self.page_footer_textHeight=0<br>††††††† <br>††††††† #print(self.status())<br>††††††† <br>††††††† if self.firstPageHeader:<br>††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.firstPageHeader))<br>
<br>††††††† if self.docTitle:<br>††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.docTitle))<br><br>††††††† if self.docPrologText:<br>††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.docPrologText))<br>
††††††††††† <br>††††††† if self.docDetailHeader:<br>††††††††††† if self.currentPageFreeHeightExceptFooter()<self.docDetailHeader.textHeight():<br>††††††††††††††† self.pageBreak()<br>††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.docDetailHeader))<br>
††††††† <br>††††††† while len(self.detailitems):<br>††††††††††† self.currentitem=self.detailitems.pop(0)<br>††††††††††† if self.currentPageFreeHeightExceptFooter()<self.currentitem.textHeight():<br>††††††††††††††† self.detailPageBreak()<br>
††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.currentitem))<br><br>††††††† if self.detailSummary:<br>††††††††††† if self.currentPageFreeHeightExceptFooter()<self.detailSummary.textHeight():<br>
††††††††††††††† self.detailPageBreak()<br>††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.detailSummary))<br><br>††††††† if self.docEndText:<br>††††††††††† if self.currentPageFreeHeightExceptFooter()<self.docEndText.textHeight():<br>
††††††††††††††† self.pageBreak()<br>††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.docEndText))<br><br>††††††† if self.docEndFooter:<br>††††††††††† if† self.currentPageFreeHeight()<self.docEndFooter.textHeight():<br>
††††††††††††††† self.pageBreak()<br>††††††††††† print(self.currentPage())† # last page number<br>††††††††††† self.rootTextCursor.insertBlock(MyTextBlockFormat(self.currentPageFreeHeight()-self.docEndFooter.textHeight()-18)) <br>
††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.docEndFooter))<br>† <br>††† def pageBreak(self):<br>††††††† if self.pageFooter:<br>††††††††††† self.rootTextCursor.insertBlock(MyTextBlockFormat(self.currentPageFreeHeightExceptFooter()))<br>
††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.pageFooter))<br>††††††† print(self.currentPage()) # current page number<br>††††††† self.rootTextCursor.setBlockFormat(self.pageBreakTextBlockFormat)<br>
††††††† if self.notFirstPageHeader:<br>††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.notFirstPageHeader))<br>††† <br>††† def detailPageBreak(self):<br>††††††† self.pageBreak()<br>††††††† if self.docDetailHeader:<br>
††††††††††† self.rootTextCursor.insertFragment(QTextDocumentFragment(self.docDetailHeader))<br>††† <br>††† def currentPageFreeHeight(self):<br>††††††† return self.max_page_height-18-self.doc.size().height()%self.max_page_height<br>
††† # repair counting -18 point (Qt BUG?) blank QDocument size.height=18 point<br>††† # and fragmentdocuments after insertion Qt don't counting rootdocument into the heights of 18 points<br>††† <br>††† def currentPageFreeHeightExceptFooter(self):<br>
††††††† return self.currentPageFreeHeight()-self.page_footer_textHeight<br>††† <br>††† def currentPage(self): #calculating currentpage number<br>††††††† currentpagecount,fragmentpagesize=divmod(self.doc.size().height(),self.max_page_height)<br>
††††††† if fragmentpagesize>0:<br>††††††††††† currentpagecount+=1<br>††††††† return currentpagecount<br><br>class FragmentTextDocument(QTextDocument):<br>††† '''document fragments rootclass:<br>††††††† -firstPageHeader<br>
††††††† -docTitle<br>††††††† -docPrologText<br>††††††† -notFirstPageHeader<br>††††††† -docDetailHeader <br>††††††† -detailitems items<br>††††††† -detailSummary<br>††††††† -docEndText<br>††††††† -docEndFooter<br>††††††† -pageFooter'''<br>
††† <br>††† def __init__(self,**kwargs):<br>††††††† super(FragmentTextDocument,self).__init__()<br>††††††† self.textdict=kwargs<br><br>††††††† self.setUseDesignMetrics(True)<br>††††††† self.setPageSize(QSizeF(793,1123))<br>
††††††† self.setDocumentMargin(0)<br>††††††† <br>††††††† self.fragmentTextEdit=QTextEdit()<br>††††††† self.fragmentTextCursor = self.fragmentTextEdit.textCursor() <br>††††††† self.fragmentTextCursor.movePosition(QTextCursor.Start)<br>
††††††† <br>††††††† self.createFormats()<br>††††††† self.detailText()<br>††††††† self.setHtml(self.fragmentTextEdit.toHtml())<br><br>††† def createFormats(self): pass #common formats<br>††††††† <br>†††††† <br>††† def detailText(self):pass #child class create document<br>
††† <br>††† <br>††† def textHeight(self):<br>††††††† return self.size().height()+2<br><br><br><u></u><u></u></p><div><p class="MsoNormal">2012/10/6 Ofek <<a href="mailto:ofek@outlook.com" target="_blank">ofek@outlook.com</a>><u></u><u></u></p>
<div><div><p class="MsoNormal">Hey,<u></u><u></u></p><p class="MsoNormal">†<u></u><u></u></p><p class="MsoNormal">I am trying to produce a text editor similar to word (paginated) in PySide.<u></u><u></u></p><p class="MsoNormal">
The way I decided to tackle this is having a QGraphicsScene with QGraphicsTextItem for each page, and to code the focus by interaction.<u></u><u></u></p><p class="MsoNormal">Now all I am trying to do now is have a box representing an A4 page, and handling textchanged events using the QGraphicsTextItem.document().pageCount() function.<u></u><u></u></p>
<p class="MsoNormal">I bumped into several issues:<u></u><u></u></p><ol start="1" type="1"><li class="MsoNormal">How can I properly define the size of the page given the QSizeF is not using any units? Will defining this right guarantee a true return value from pageCount()?<u></u><u></u></li>
<li class="MsoNormal">If I define a pageSize at all, QGraphicsTextItem stops expanding. How can I set a fixed size so It'll look like a page?<u></u><u></u></li></ol><p class="MsoNormal">†<u></u><u></u></p><p class="MsoNormal">
Documentation for Qt is extremely light and I could not figure anything out of it.<u></u><u></u></p><p class="MsoNormal">†<u></u><u></u></p><p class="MsoNormal">Thanks!<u></u><u></u></p></div></div><p class="MsoNormal" style="margin-bottom:12.0pt">
<br>_______________________________________________<br>PySide mailing list<br><a href="mailto:PySide@qt-project.org" target="_blank">PySide@qt-project.org</a><br><a href="http://lists.qt-project.org/mailman/listinfo/pyside" target="_blank">http://lists.qt-project.org/mailman/listinfo/pyside</a><u></u><u></u></p>
</div><p class="MsoNormal"><u></u>†<u></u></p></div></div></div></div></blockquote></div><br>