This program has a simple list widget. How do I change the background color of any specific item in the list without it being clicked?
from PyQt5 import QtWidgets, uic, QtGui
import threading
app = QtWidgets.QApplication([])
ui = uic.loadUi("app.ui")
update_ui = True
ui.lst_positions.addItem("Item 1")
ui.lst_positions.addItem("Item 2")
ui.lst_positions.addItem("Item 3")
def ui_update():
while update_ui == True:
# Updating labels works fine with threading
ui.lbl_in_position.setText("Random text")
# This does not work with threading
item = ui.lst_positions.item(1)
item.setBackground(QtGui.QColor("red"))
ui_thread = threading.Thread(target=ui_update)
ui_thread.daemon = True
ui_thread.start()
ui.show()
app.exec()