Problems with Open-Source Downloads read https://www.qt.io/blog/problem-with-open-source-downloads and https://forum.qt.io/post/638946

Qt SqlTableModel - icon and background gradient



  • I wish my filtered column show an icon and background gradient.

    css an example:

    @background: qlineargradient (x1: 0, y1: 0, x2: 0, y2: 1,
    stop: 0 # f9f9f8, stop: 1 # edece6);@

    my code:

    @class MySubClassedSqlTableModel : public QSqlTableModel
    {
    Q_OBJECT
    public:
    MySubClassedSqlTableModel(QObject * parent = 0, QSqlDatabase db = QSqlDatabase())
    : QSqlTableModel(parent,db) {;}
    QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const
    {
    if(role==Qt::BackgroundColorRole)
    {
    const QVariant value(data(index,Qt::DisplayRole));
    if(value.toString()=="S"){
    return QVariant(QColor("#d0ffe3")); //<<background Gradient and icon1?
    }else if (value.toString()=="O"){
    return QVariant(QColor("#ffe3d0")); //<<background Gradient and icon2?
    }else if (value.toString()=="R"){
    return QVariant(QColor("#fffad0")); //<<background Gradient and icon3?
    }
    }
    return QSqlTableModel::data(index,role);
    }@

    Someone could help me?


Log in to reply