[英]Read specific text in an updating qtextbrowser
在python中,我有一個QtextBrowser,它被饋送給外部命令的輸出。 這很好用在輸出中是一個進度更新:
loadingfile
processing file
progress 5%
progress 10%
progress 25%
....
closing file
processing completed
我想在QTextBrowser中查詢“進度X%”行,並將該值輸入到更新進度欄中。
我如何閱讀最新進度%? 我以為我會在每次更新瀏覽器時都讀最后一行來做到這一點,但是我找不到任何方法來做到這一點。 我假設我必須將文本轉換為Qstringlist: textBrowser.toPlainText()
,然后進行處理?
雖然我確信這不是解決問題的最有效方法-但我有一個可行的解決方案:
doc = self.textBrowser.toPlainText()
txt= str(doc).split('\n')
match = 'progress '
for prog in txt:
if match in text:
prog = prog.strip('progress ')
prog = prog.translate(None, '%')
prog = int(prog)
self.progressBar.setValue(prog)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.