2016-01-28 140 views
1

我有我認爲是PySide小部件重繪問題。我怎樣才能強迫小部件(或整個窗口/應用程序)重繪在方法的中間?如何在PySide中強制重繪?

def on_button_clicked(): 

    window.resultTextEdit.setPlainText("Parsing file...") 
    # indicate delay, this message should be visible while parsing 
    # but in fact it never appears 

    # can I force a repaint here? 

    result = parse() # (takes a little while) 

    window.resultTextEdit.setPlainText(result) 
    # display the results once done 

app = QApplication(sys.argv) 
window = QtUiTools.QUiLoader().load("application.ui") 
window.userButton.clicked.connect(on_button_clicked) 
window.show() 
sys.exit(app.exec_()) 
+0

http://stackoverflow.com/a/11806126/4720935 – Mel

+0

@Mel莫大的聯繫,謝謝!我已經提取了相關位作爲下面的答案 – d3vid

回答

1

對於任何需要在事件中重繪的窗口小部件,可以簡單地調用widget.repaint()。請注意,在重新繪製期間,UI的其餘部分沒有響應(這對於一次性調用來說很好,但如果重複重新繪製,則不會)。

(感謝梅爾指着我https://stackoverflow.com/a/11806126/4720935