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. QTableview Change Row Color
Qt 6.11 is out! See what's new in the release blog

QTableview Change Row Color

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.7k 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.
  • M Offline
    M Offline
    mrcgnerd
    wrote on last edited by
    #1

    Hallo, I am new in Qt and C++, and I have a question:

    I have Tableview wich is set to QSqlQueryModel. MySql Table structure looks like this:

    ID | VALUE | NAME|
    1 _____1 ___Tom
    2 _____0 ___Mark
    3 _____0 ___Rita
    4 _____1 ___Sam

    @this->model1 = new QSqlQueryModel();
    model1->setQuery("SELECT ID, value, Name FROM DB_Table ");
    ui->tableView->setModel(model1);@

    I want to change color of the rows there VALUE = 1, for example make it red.

    I can't get it how can i do it ? I even can't find a way to manualy change color o one row for example:

    Tableview->Row(1)->SetColor(QColor); // Can I do something similar ?

    Sory for my English.

    Thank you.

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

      Hi and welcome to devnet,

      If you don't change your data you can use a "QIdentityProxyModel":http://qt-project.org/doc/qt-5/qidentityproxymodel.html

      Hope it helps

      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