Hi,

I have been trying to extract information from a QTextEdit object using code, but run in to problems iterating the elements inside a QTextDocument. It seams like there is no way to get to the next element after starting iterating using the rootFrame.begin() method. If you examine the metgod list using dir(titer), you will find that it is missing the __iadd__ and __isub__ methods in PySide. It is missing in the documentation as well.

http://www.pyside.org/docs/pyside/PySide/QtGui/QTextFrame.iterator.html is missing __iadd__ and __isub__ http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qtextframe-iterator.html is having both a __iadd__ and an __isub__

I have attached a example that works fine in PyQt4 but not in PySide.

Here is the method not working:
    def rebuildtree(self):
        self.rtree.clear()
        tdoc = self.redit.document()
        rframe = tdoc.rootFrame()
        titer = rframe.begin()
        while not titer.atEnd():
            tb = titer.currentBlock()
            if tb:
                treeitem = QtGui.QTreeWidgetItem(self.rtree)
                scontent = 'a text block (%s)' % tb.text()
                treeitem.setText(0, scontent)
            else:
                tf = titer.currentFrame()
                treeitem = QtGui.QTreeWidgetItem(self.rtree)
                treeitem.setText(0, 'a frame')
            res = dir(titer) # This one is missing the __iadd__ in PySide
titer.__iadd__(1) #This can be used in PyQt4 but not found in PySide


Is this a bug or have I missed out on another smarter way of getting the next element using the iterator.

Thanks,
Bjorn Helge Kjosnes
from PySide import QtCore, QtGui
#from PyQt4 import QtCore, QtGui

class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.main = QtGui.QWidget()
        self.mlay = QtGui.QHBoxLayout()
        self.redit = QtGui.QTextEdit()
        self.rtree = QtGui.QTreeWidget()
        self.mlay.addWidget(self.redit)
        self.mlay.addWidget(self.rtree)
        self.main.setLayout(self.mlay)
        self.setCentralWidget(self.main)
        
QtCore.QObject.connect(self.redit,QtCore.SIGNAL('textChanged()'),self.textchanged)
        
    def textchanged(self):
        self.rebuildtree()
    
    def rebuildtree(self):
        self.rtree.clear()
        tdoc = self.redit.document()
        rframe = tdoc.rootFrame()
        titer = rframe.begin()
        while not titer.atEnd():
            tb = titer.currentBlock()
            if tb:
                treeitem = QtGui.QTreeWidgetItem(self.rtree)
                scontent = 'a text block (%s)' % tb.text()
                treeitem.setText(0, scontent)
            else:
                tf = titer.currentFrame()
                treeitem = QtGui.QTreeWidgetItem(self.rtree)
                treeitem.setText(0, 'a frame')
            res = dir(titer)
            titer.__iadd__(1)
        
        

if __name__ == '__main__':
    import sys

    app = QtGui.QApplication(sys.argv)
    mainWin = MainWindow()
    mainWin.show()
    sys.exit(app.exec_())
_______________________________________________
PySide mailing list
PySide@lists.openbossa.org
http://lists.openbossa.org/listinfo/pyside

Reply via email to