<div dir="ltr">Hi<div><br></div><div>I am trying to test my pyqt gui application which has a QTextBrowser with hyper link anchors in it. I need to figure out a way to click on these anchors (preferably using QTest). To do this I decided to save the anchor location each time I created one using QTextBrowser.cursorRect() however this function is broken. Below I have replicated the code using QTextEdit():</div><div><br></div><div><div>>>> ll = QtGui.QTextEdit()</div><div>>>> ll.cursorRect()</div><div>PyQt4.QtCore.QRect(0, 0, 1, 10)</div><div>>>> ll.textCursor().position()</div><div>0</div><div>True</div><div>>>> ll.insertPlainText('move the cursor')</div><div>>>> ll.cursorRect()</div><div>PyQt4.QtCore.QRect(112, 4, 1, 17)</div><div>>>> ll.textCursor().position()</div><div>15</div><div>>>> ll.append('<a href  =' +'hhee'+'>'+'hhee'+ '</a>')</div><div>>>> ll.textCursor().position()</div><div>20</div><div>>>> ll.cursorRect()</div><div>PyQt4.QtCore.QRect(37, 21, 1, 17)</div></div><div><u><br></u></div><div>As you can see cursorRect() works fine with QtGui.QTextEdit() I then ran the same sequence using QTextBrowser() instead:</div><div><br></div><div><div>>>> ll = QtGui.QTextBrowser()</div><div>>>> ll.textCursor().position()</div><div>0</div><div>>>> ll.cursorRect()</div><div>PyQt4.QtCore.QRect(0, 0, 1, 10)</div><div>>>> ll.append('<a href  =' +'hhee'+'>'+'hhee'+ '</a>')</div><div>>>> ll.textCursor().position()</div><div>4</div><div>>>> ll.cursorRect()</div><div>PyQt4.QtCore.QRect(0, 0, 1, 10)</div><div>>>> ll.insertPlainText('move the cursor')</div><div>>>> ll.textCursor().position()</div><div>19</div><div>>>> ll.cursorRect()</div><div>PyQt4.QtCore.QRect(0, 0, 1, 10)</div></div><div><br></div><div>As you can adding text to a QTextBrowser updates textCursor().position but doesn't change the position returned by cursorRect(). </div><div><br></div><div>In conclusion cursorRect() appears to be broken for QTextBrowser. Could you please tell me what I am doing wrong or fix this issue. Alternatively could you recommend a better way I could click on every single anchor in my QTextBrowser. I need to be able to do so to test my application</div><div><br></div><div>Thanks</div><div>John</div><div><br></div><div><br></div></div>