Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSqlQueryModel text color



  • 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()) ?


  • Qt Champions 2017

    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.


  • Lifetime Qt Champion

    Hi,

    QSqlQueryModel is a read only model

    You have two options here:
    QStyledItemDelegate
    QIdentityProxyModel



  • Thanks a lot.
    I'll try it.


Log in to reply