如何在PySide中强制重绘?

时间:2016-01-28 11:01:47

标签: python user-interface pyside paint

我认为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_())

1 个答案:

答案 0 :(得分:1)

对于在活动过程中需要重新绘制的任何窗口小部件,您只需拨打widget.repaint()即可。请注意,其余的UI在重绘期间没有响应(这对于一次性通话是好的,但如果您重复重新绘制则不行。)

(感谢Mel指点我https://stackoverflow.com/a/11806126/4720935