Search code examples
qtqt4pyqtpyqt4qtablewidget

changing cell background color in qt


i'm new to pyqt , and i'm still facing some newbie problems :D
i have a QTableWidget that is item delegated on a QChoice control ( hope i said it right ) i need to have the cell background color changes whenever a user change the choice control selection
briefly: how to change a cell background color in a table widget ??
i use pyqt4 and python 2.6
thanx in advance


Solution

  • Use

    QTableWidgetItem QTableWidget.item(row, column)
    

    and

    QTableWidgetItem setData(role, data)
    

    with

    Qt.BackgroundRole
    

    as follows:

    table.item(0, 0).setData(Qt.BackgroundRole, color).
    

    And read about the Roles mechanism used in Qt Model/View.