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. Set text color for QTableWidget cell widget when cell selected.

Set text color for QTableWidget cell widget when cell selected.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 2.1k 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by
    #1

    I have a date edit widget that is assigned as the cell widget for my QTableWidget. As you can see in the attached screenshot, the second column text turns white when the row is selected but my custom widget in the first column obviously stays black.

    I want the custom widget to change its text color using the palette in the same way that a normal QTableWidgetItem does when the row is selected.

    What is the best way to do this? Just set the color manually when the selected row changes, or a more comprehensive one which integrates the palette of the custom widget and the table a little better?

    Thanks!

    0_1522954565350_2018-04-05_11-51-16.jpg

    https://alaskafamilysystems.com/

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @patrickkidd said in Set text color for QTableWidget cell widget when cell selected.:

      What is the best way to do this?

      Don't use setItemWidget. The default editor factory already handles QDates with a QDateEdit. Ther's no need to do anything special to have a date editor in your cell containing QDate

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2
      • P Offline
        P Offline
        patrickkidd
        wrote on last edited by
        #3

        The QDateEdit is quite clunky and incomplete so I customized it for my needs.

        https://alaskafamilysystems.com/

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          Then just subclass QStyledItemDelegate and make createEditor return your editor

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          2

          • Login

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