PDA

View Full Version : repaint a cell or row in QTableWidget



alphaqt
3rd March 2006, 13:08
Hello everyone,

I have a QTableWidget (3 columns,rows are added by a loop).
I would like to know if it is possible to repaint a cell,or a row, without repainting the whole table.
I have read that method repaint() can't be used in a QTableWidgetItem.

If anyone has an idea please let me know.

Thanks

wysota
3rd March 2006, 13:21
Use update() with parameters set to your item's rectangle (visualItemRect());

BTW. Try to avoid using repaint() if possible.

jpn
3rd March 2006, 13:22
First, get the rectangle occupied an item by QTableWidget::visualItemRect() (http://doc.trolltech.com/4.1/qtreewidget.html#visualItemRect).
Then you can update this specific area in your table widget by QWidget::update() (http://doc.trolltech.com/4.1/qwidget.html#update-3).

alphaqt
3rd March 2006, 17:39
thank u all for your answers.
my pb with method update is :
"This function does not cause an immediate repaint; instead it schedules a paint event for processing when Qt returns to the main event loop."

in fact i want immediate repainting.
when a new row is added, it is highlighted directly (background in red, then after white)

thanks

jpn
3rd March 2006, 18:29
Hmm, then try processing all pending events after updating:

void QCoreApplication::processEvents ( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) [static]

wysota
3rd March 2006, 18:46
in fact i want immediate repainting.
when a new row is added, it is highlighted directly (background in red, then after white)


It will be immediate -- for your eyes. In reality it'll be a few miliseconds later, but I'm sure you won't notice :) The point is that each repaint() is executed immediately and two or more update() calls can be "merged", resulting in much more efficient painting. That's why it's better to use update() (and probably why repaint() is protected).

vvanirudh
26th June 2012, 12:21
Use update() with parameters set to your item's rectangle (visualItemRect());

BTW. Try to avoid using repaint() if possible.

can u give a simple snippet of code showing how to use the update() and visualitemrect() functions. I am facing a similar problem too. Give a snippet of code wherein i have to update a column(every element in the column) in the table with time.

Thanks!!