[SOLVED]How to set the background color of a cell in QTableWidget while editing?



  • I have a editable, spreadsheet-like table created using QTableWidget with QTableWidgetItems. It is functionally doing exactly what I wish it to do. I have set the QTableWidgetItems to be editable. However, I am having problem with setting the background color of the cells while editing.

    I have set the color of the background color of the cells and the current selected cells using stylesheets.

    @
    QTableWidget::item {
    background-color: green;
    }

    QTableWidget::item:selected {
    background-color: red;
    }
    @

    Once I double click on the cell to edit the contents of the QTableWidgetItem, the color of the background will change to white. I wish the color to remain while the user is editing the cell. Focus, and edit-focus did not help to set the background color of the editing cell.

    @
    QtableWidget::item:focus {
    background-color: yellow;
    }

    QtableWidget::item:edit-focus {
    background-color: yellow;
    }
    @

    I am on a Windows 7/xp machine, using qt-mingw 5.2.1 build.



  • Hey,

    the default delegate uses a QLineEdit, so just define a style for it:

    QLineEdit {
    background: yellow;
    }

    bb



  • It works, thank you!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.