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. How to change the text color of a specific row in a QTreeWidget?

How to change the text color of a specific row in a QTreeWidget?

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

    What i tried:

    auto model = ui.treeWidget->model()->index(0, 0);
    auto item = ui.treeWidget->itemFromIndex(model);
    auto font = item->font(0);
    //   font.  ???
    

    Am I on the correct path? looking for help on this question.

    jsulmJ 1 Reply Last reply
    0
    • N n34rt

      What i tried:

      auto model = ui.treeWidget->model()->index(0, 0);
      auto item = ui.treeWidget->itemFromIndex(model);
      auto font = item->font(0);
      //   font.  ???
      

      Am I on the correct path? looking for help on this question.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @n34rt said in How to change the text color of a specific row in a QTreeWidget?:

      Am I on the correct path?

      No, because QFont does not specify text color.
      https://doc.qt.io/qt-6/qtreewidgetitem.html#setForeground is what you're looking for...

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      N 1 Reply Last reply
      5
      • jsulmJ jsulm

        @n34rt said in How to change the text color of a specific row in a QTreeWidget?:

        Am I on the correct path?

        No, because QFont does not specify text color.
        https://doc.qt.io/qt-6/qtreewidgetitem.html#setForeground is what you're looking for...

        N Offline
        N Offline
        n34rt
        wrote on last edited by n34rt
        #3

        @jsulm I'm trying to change the color of only the text, setForeground will change the color of other things along the text?

        jsulmJ 1 Reply Last reply
        0
        • N n34rt

          @jsulm I'm trying to change the color of only the text, setForeground will change the color of other things along the text?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @n34rt Depends on what is in the cell, see https://doc.qt.io/qt-6/qtreewidgetitem.html#foreground
          Why don't you simply try it out to see whether it does what you want?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          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