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 subclass && QLinearGradient in a cell
Forum Updated to NodeBB v4.3 + New Features

QSqlQueryModel subclass && QLinearGradient in a cell

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 889 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.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    Hi all,
    I subclassed a QSqlQueryModel to change some color of a cell in a QTableView.

    This is my code:
    @
    QVariant CustomQueryModel::data(const QModelIndex &index, int role) const
    {
    switch(role)
    {
    case Qt::BackgroundRole:
    if(index.column()==8 && index.isValid())
    {
    QLinearGradient grad(0,0,1,0);
    grad.setCoordinateMode(QGradient::ObjectBoundingMode);
    grad.setColorAt(0.0, QColor(200,50,50));
    grad.setColorAt(0.5, QColor(50,200,50));
    grad.setColorAt(1.0, QColor(50,200,50));
    return QBrush(grad);
    }
    break;
    default:
    return QSqlQueryModel::data(index,role);
    }
    return QSqlQueryModel::data(index,role);
    }

    @

    As you can see I want a linear gradient in the cells on column 8.

    The problem is that the gradient isn't displayed, it only set the cell's color on QColor(200,50,50).
    The gradient is shown correctly if I set it on the column 1:
    @
    QVariant CustomQueryModel::data(const QModelIndex &index, int role) const
    {
    switch(role)
    {
    case Qt::BackgroundRole:
    if(index.column()==1 && index.isValid())
    {
    QLinearGradient grad(0,0,1,0);
    grad.setCoordinateMode(QGradient::ObjectBoundingMode);
    grad.setColorAt(0.0, QColor(200,50,50));
    grad.setColorAt(0.5, QColor(50,200,50));
    grad.setColorAt(1.0, QColor(50,200,50));
    return QBrush(grad);
    }
    break;
    default:
    return QSqlQueryModel::data(index,role);
    }
    return QSqlQueryModel::data(index,role);
    }
    @
    it seems to be a coordinates problem but I don't know how to solve it.

    Can you help me?

    Thanks

    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