Iám still struggle to get the cells background to blink in the model with a timer.
I have a customslot declared in the customsqlmodel.h (see code below).
public:
CustomSqlModel
(QObject *parent
= 0);
public slots:
void dataChanged
(const QModelIndex &topLeft,
const QModelIndex &bottomRight
);
// I don't no this is the right slot
private:
CustomSqlModel *model;
public:
CustomSqlModel(QObject *parent = 0);
QVariant data(const QModelIndex &index, int role) const;
public slots:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); // I don't no this is the right slot
private:
CustomSqlModel *model;
To copy to clipboard, switch view to plain text mode
In my customsqlmodel.cpp(see code below).
CustomSqlModel
::CustomSqlModel(QObject *parent
){
connect(timer, SIGNAL(timeout()), this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&))); //Can i connect the timer to the dataChanged() slot on this way?
timer->start(1000);
//a custom slot
connect(model,
SIGNAL(dataChanged
(const QModelIndex
&,
const QModelIndex
&)),
this,
SLOT(dataChanged
(const QModelIndex &topLeft,
QModelIndex &bottomRight
)));
}
{
if (role == Qt::BackgroundColorRole)
{
int val = index.model()->data(index, Qt::DisplayRole).toInt() < 1;
if(index.column() == 8 && val )
return qVariantFromValue
(QColor(Qt
::yellow));
// Want to blink these color with a timer into the custom slot dataChanged(). return qVariantFromValue
(QColor(Qt
::grey));
}
return value;
}
{
// What to put here.
emit dataChanged(topLeft, bottomRight); //?
}
CustomSqlModel::CustomSqlModel(QObject *parent)
: QSqlTableModel(parent)
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(dataChanged(const QModelIndex&, const QModelIndex&))); //Can i connect the timer to the dataChanged() slot on this way?
timer->start(1000);
//a custom slot
connect(model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(dataChanged(const QModelIndex &topLeft, QModelIndex &bottomRight)));
}
QVariant CustomSqlModel::data(const QModelIndex &index, int role) const
{
QVariant value = QSqlTableModel::data(index, role);
if (role == Qt::BackgroundColorRole)
{
int val = index.model()->data(index, Qt::DisplayRole).toInt() < 1;
if(index.column() == 8 && val )
return qVariantFromValue(QColor(Qt::yellow)); // Want to blink these color with a timer into the custom slot dataChanged().
return qVariantFromValue(QColor(Qt::grey));
}
return value;
}
void CustomSqlModel::dataChanged(const QModelIndex &topLeft, QModelIndex &bottomRight)
{
// What to put here.
emit dataChanged(topLeft, bottomRight); //?
}
To copy to clipboard, switch view to plain text mode
Can someone give my some example code.
I tried severall things but nothings works.
Thanks in advance.
Bookmarks