PDA

View Full Version : Problem in Paint Focus for Q3Table



Hans
6th February 2013, 23:55
I had a class MyTable inherited from Q3Table.
I want to highlight the cell that's clicked by mouse by adding a red rectangular around the cell's bundary.
So I re-implemented paintFocus(QPainter * p, const QRect & cr) like this:

void MyTable::paintFocus ( QPainter * painter, const QRect & cr )
{
Q3Table::paintFocus(painter,cr);
painter->setPen(QPen(QColor(155,10,10), 2));
QRect highlight_rect = cr.adjusted(2,2, -2, -2);
painter->drawRect(highlight_rect);
update();
}

But the red Rect only appear for the first column in the first row. When clicking other cells, just the default black frame.
Why????????
8685 8686

Hans
7th February 2013, 19:38
simply put, given the col and row number, how to hight light the cell?

norobro
7th February 2013, 20:13
From the Q3Table::paintFocus() docs:
The painter p is already translated to the cell's origin, ...

ChrisW67
8th February 2013, 23:23
Try removing the call to QWidget::update() because all this Qt 3 compatibility code is likely called from within QWidget::paintEvent() of the Qt4 widget wrapper and, as the docs say:


Note: Generally, you should refrain from calling update() or repaint() inside a paintEvent(). For example, calling update() or repaint() on children inside a paintevent() results in undefined behavior; the child may or may not get a paint event.



If you are writing a new program do not continue use the Qt 3 compatibility classes. Learn to use the Qt4/5 QTableWidget or QTableView.