PDA

View Full Version : cell not updating in table Widget afterclicking on it



quickNitin
6th September 2006, 06:47
greetings qt users and developers,

I had created a table Widget. Whenever i click on any cell of table, it is highlighted with certain color at background. Now if i click at some other cell previous celll will show data but printed with some offset in pixels resulting in blurred or not-refreshed view.

quickNitin

jpn
6th September 2006, 07:04
How do you set/unset the highlighting? The view should update itself correctly if you simply use QTableWidgetItem::setBackgroundColor() or similar.

But, if you are drawing a custom highlight, the problem might be for example that the model doesn't really change anyhow and the view doesn't know to update itself. I did some custom highlight effect back then and used

setDirtyRegion(visualItemRect(item));
to manually schedule item's area to be updated. Doesn't look or feel very elegant but it works.

From docs:


void QAbstractItemView::setDirtyRegion ( const QRegion & region ) [protected]
Marks the given region as dirty and schedules it to be updated. You only need to call this function if you are implementing your own view subclass.
This function was introduced in Qt 4.1.

quickNitin
6th September 2006, 10:06
How do you set/unset the highlighting? The view should update itself correctly if you simply use QTableWidgetItem::setBackgroundColor() or similar.



i had done this only. No custom highlight. only setting of background color. So i was thinking i had put anything for refreshing?

wysota
6th September 2006, 10:45
Can we see the code?

quickNitin
6th September 2006, 11:40
here is snap of code which is responsible for posting data to table widget elements


QLabel *lb;
.
.
.
lb=dynamic_cast<QLabel*>(tw.cellWidget(row,col));
lb->setText(QString::number(y));
lb->setBackGroundColor(Qt::Blue);
col++;
lb=dynamic_cast<QLabel*>(tw.cellWidget(row,col));
lb->setText(QString::number(x));

jpn
6th September 2006, 12:51
You can either set the background color directly for the item: QTableWidgetItem::setBackgroundColor() (and not for the label),
or you can make the label to fill it's background: QWidget::setAutoFillBackground() (child widgets are transparent by default since 4.1).

PS. QWidget::setBackgroundColor() (http://doc.trolltech.com/4.1/qwidget-qt3.html) is some obsolete Qt3 support member and advised against using.

wysota
6th September 2006, 15:01
Do you need those labels at all?

quickNitin
7th September 2006, 09:22
i am using Qlable to set text on cell of table. As u have given hint there may be other way also i weill look for that also.

jpn
7th September 2006, 09:55
It is sometimes useful to take a glance at the docs before implementation.. QTableWidgetItem::setText().

quickNitin
7th September 2006, 22:39
since at time of creation of tableWidget i used used QLable as cell item , so that followed . I am updating to QTableWidgetItem

wysota
7th September 2006, 23:11
Why did you do that in the first place?

quickNitin
7th September 2006, 23:15
just because while going through doc i came through one such example. ALso my requirment was to display text only in widget. So i followed it. No other reason.