简体   繁体   中英

How can I force a repaint in PySide?

I have what I think is a repainting issue with a PySide widget. How can I force the widget (or the whole window/app) to repaint in the middle of a method?

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_())

For any widget that needs a repaint in the middle of an event, you can simply call widget.repaint() . Note that the rest of UI is unresponsive during the repaint (which is fine for a one-off call, but not if you're repainting repeatedly).

(Thanks Mel for pointing me to https://stackoverflow.com/a/11806126/4720935 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM