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. QSqlQueryModel text color
Forum Updated to NodeBB v4.3 + New Features

QSqlQueryModel text color

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.2k 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
    Mr1Penguin
    wrote on last edited by
    #1

    Hello. Can't find answer so I created this post.

    I want to change text color in column A to (example) red if date in column B more than currentDate.
    Already tried to reimplement QSQM::data(...) but seems it wasn't called.
    Also tried to use model->setData(index, QColor(Qt::red), Qt::ForegroundColor)..

    There are any solutions instead using QStandardItemModel and fill it via while(qry.next()) ?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      You are trying to customise the behaviour of individual cell based on the data. You need to write you customDelegate for this to make it work. Please look at how to write custom delegate and set the same for view.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

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

        Hi,

        QSqlQueryModel is a read only model

        You have two options here:
        QStyledItemDelegate
        QIdentityProxyModel

        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
        • M Offline
          M Offline
          Mr1Penguin
          wrote on last edited by
          #4

          Thanks a lot.
          I'll try it.

          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