Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]How to set the background color of a cell in QTableWidget while editing?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    qtnewbie12345
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Saugglocke
      wrote on last edited by
      #2

      Hey,

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

      QLineEdit {
      background: yellow;
      }

      bb

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtnewbie12345
        wrote on last edited by
        #3

        It works, thank you!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved