October 26, 2011

toho71 toho71
Lab Rat
189 posts

[SOLVED]Blink text in table

 

I got at tableview with items from a model.

Some of the rows should “Blink”
Just like in html and the Blink tag

I Use a QBrush (myBlink) to set the color of the text.

In a timerevent I simple change the Qbrush (myBlink) color but nothing happens.

I know that the timerevent runs.

I have tried to repaint the tabelview but nothing happens.

is it possible to do like this:
Maybe i should use the paintevent or something;
pls help

6 replies

October 26, 2011

Gerolf Gerolf
Area 51 Engineer
3212 posts

if you have a custom model (so using the QTableView, not QTableModel), you could change the data in the model and send dataCHanged signal. If you use the widgets style (QTableWidget) you can change the background color for the item in the widget. it should update immediatly.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

October 26, 2011

toho71 toho71
Lab Rat
189 posts

Thank you but i don’t think that this is the solution.(Maybe!)
I suppose that I have to loop thru the whole model if I use your replay.
and set the datamodels data.

That’s a final solution that I hope to avoid

October 26, 2011

peppe peppe
Ant Farmer
1026 posts

You can’t avoid that solution. You MUST emit dataChanged with a proper range in order to make the view fetch the new values for the foreground text color (then provide the new color in data()).

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

October 26, 2011

toho71 toho71
Lab Rat
189 posts

Ok I try

Any cute loop to use
Maybe

  1. foreach(datamodel.rowcount,datamodel.columnCount){}

or

October 27, 2011

Gerolf Gerolf
Area 51 Engineer
3212 posts

Do you have a standard model or a custom one?

If you have a custom model, it’s fairly trivial. Yust store the data inside it and call

  1.     emit dataChanged(createIndex(firstRow, blinkColumn), createIndex(lastRow, blinkColumn));

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

November 1, 2011

toho71 toho71
Lab Rat
189 posts

I solved it in my own way.

  1. void Logs::BlinkTextRows()
  2.  
  3. {
  4.  
  5.     int row_count = model->rowCount();
  6.     int col_count = model->columnCount();
  7.  
  8.     QModelIndex index;
  9.  
  10.  
  11.     for( int i = 0; i < row_count; i++ )
  12.     {
  13.            if (model->item(i,3)->data(Qt::DisplayRole).toString().compare("yes",Qt::CaseInsensitive) == 0)
  14.            {
  15.                     if (model->item(i,4)->data(Qt::CheckStateRole) == Qt::Unchecked)
  16.                     {
  17.                       for (int j = 0;j < col_count;j++)
  18.                       {
  19.                           index = model->indexFromItem(model->item(i,j));
  20.                           if (hidden)
  21.                               model->setData(index, myblink, Qt::ForegroundRole);
  22.                           else
  23.                               model->setData(index, myblink, Qt::ForegroundRole);
  24.                       }//for
  25.                    } //if model..
  26.               } //if compare
  27.     }//For i
  28.  
  29.     if (hidden)
  30.         hidden = false;
  31.     else
  32.         hidden = true;
  33. }

It wasn’t so hard in the end

 
  ‹‹ QPSQL not loaded      Unwanted padding around QHBoxLayout ››

You must log in to post a reply. Not a member yet? Register here!