我创建了一个QTextBrowser来在代码中显示html表。但是当我试图使用setTextCursor方法将光标移动到特定的行时,它没有做到。在
文本浏览器的滚动条确实移动了,但没有移动到特定的行。这个问题和html表有关吗?在import sys
from PyQt5.QtGui import QTextCursor
from PyQt5.QtWidgets import QWidget, QTextBrowser, QMainWindow, QPushButton, QHBoxLayout, QApplication
class MyTextBrowser(QTextBrowser):
def __init__(self, parent = None):
super(MyTextBrowser, self).__init__(parent)
self.createTable()
def createTable(self, line_num = 1):
# Create an html table with 100 lines
html = '
for i in range(0, 100):
# Highlight specified line
if line_num == i+1:
html += '
Line%d' % (i+1)else:
html += '
Line%d' % (i+1)html += '
'self.setHtml(html)
# Move the cursor to the specified line
c