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. Change font color of Qtableview text when onclick()

Change font color of Qtableview text when onclick()

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.5k Views 1 Watching
  • 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.
  • saeedhardanS Offline
    saeedhardanS Offline
    saeedhardan
    wrote on last edited by
    #1

    Hi,
    i want to implement QTableview ondoubleclick() method .
    the method only takes :
    @
    const QModelIndex &index
    @

    and i have the model for the qtableview .

    how can i edit the text color in a certain cell in the qtableview inside the ondoubleclick() ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean have a color editor or just change the color of the cell ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • saeedhardanS Offline
        saeedhardanS Offline
        saeedhardan
        wrote on last edited by
        #3

        sorry for late reply ,
        i don't exactly know what a color editor is , but what i want is to be able to change the text color in the cells of the tableview , the default know is black .
        lets say i have a column of IDs , and one of the ids is 123456 , this is the text i want to change its color 123456 .

        1 Reply Last reply
        0
        • Pradeep P NP Offline
          Pradeep P NP Offline
          Pradeep P N
          wrote on last edited by
          #4

          Hi,

          If you want to change the color of the letters shown in table, you should check out setting the Qt::ForegroundRole on the cell you want to be colored.

          Pradeep Nimbalkar.
          Upvote the answer(s) that helped you to solve the issue...
          Keep code clean.

          1 Reply Last reply
          2
          • saeedhardanS Offline
            saeedhardanS Offline
            saeedhardan
            wrote on last edited by
            #5

            thanks that worked , i just used :

            @
            QStandardItem *col_2 = new QStandardItem(QString(tr((*it)->description.c_str())));
            col_2->setForeground(Qt::red);
            @

            now its a bit tricky , is it possible to color some of the text ? not the whole cell's ForegroundRole ?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              For that second port you should rather create a custom QStyledItemDelegate where you'll be able to customize the painting to your needs

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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