如何自动滚动到我的底部QTextEdit
在我的GUI初始化函数中
self.mytext = QTextEdit()
self.cursor = QTextCursor(self.mytext.document())
self.mytext.setTextCursor(self.cursor)
Run Code Online (Sandbox Code Playgroud)
以及我如何在另一个函数中添加它
self.cursor.insertText(str(self.user) + ": " + str(self.line.text()) + "\n")
Run Code Online (Sandbox Code Playgroud) 你好我的PyQT QTextEdit遇到了一个相当奇怪的问题.当我从我的QLineEdit输入一个字符串时,它会添加它但是说我输入另一个字符串消失了我假设那是因为我没有附加文本.知道我怎么能这样做吗?
这是相关的代码
self.mytext.setText(str(self.user) + ": " + str(self.line.text()) + "\n")
而重要的一个
self.mySignal.emit(self.decrypt_my_message(str(msg)).strip() + "\n")
编辑*
我想通了我需要使用QTextCursor
self.cursor = QTextCursor(self.mytext.document())
self.cursor.insertText(str(self.user) + ": " + str(self.line.text()) + "\n")
*干杯
如何检查文件中是否存在行,如果使用Python不存在,则将该行写入文件
这是我目前的尝试
logfile = open('ip.log', 'a+')
while 1:
line = logfile.readline()
#line.replace("\n", "")
print line
if line == str(self.CLIENT_HOST):
print "Line Found Skipping"
else:
logfile.write(str(self.CLIENT_HOST)+"\n")
if not line:
print "EOF Reached"
break
print line
logfile.close()
干杯