-
Bug
-
Resolution: Cannot Reproduce
-
Not Evaluated
-
4.6.0
-
None
Product
Qt
Function
Itemviews
Version
4.6.0-tp
Platform
Mac OS X
Platform details
8-core Xeon Mac Pro, Snow Leopard
Compilers
GCC
Compiler details
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646)
Subject
QItemDelegate::paint() doesn't get called for first row of table when moving current-cell left or right via arrow-keys
Steps to reproduce / test case
1) Open $QTDIR/examples/itemviews/addressbook/addresswidget.cpp in your text editor
2) Add the following code, just below the #include lines:
class TestItemDelegate : public QItemDelegate
{
public:
TestItemDelegate(QTableView * tv = 0) : QItemDelegate(tv), _tableView(tv)
virtual void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
printf("TestItemDelegate::paint() called! row=%i column=%i\n", index.row(), index.column());
if (option.state & QStyle::State_Selected)
{
QStyleOptionViewItem o = option;
if (option.state & QStyle::State_Selected) MakeHighlightPalette(index, _tableView->currentIndex(), o.palette);
QItemDelegate::paint(painter, o, index);
}
else QItemDelegate::paint(painter, option, index);
}
void MakeHighlightPalette(const QModelIndex & idx, const QModelIndex & curIdx, QPalette & p) const
{
QVariant v = idx.data(Qt::BackgroundRole);
QColor bc = (v.type() == QVariant::Color) ? v.value<QColor>() : qApp->palette().color(QPalette::Active, QPalette::Base);
bc.setRed((bc.red()*4)/5);
QColor hc = bc.dark((idx==curIdx)?100:120);
if (hc == Qt::black) hc = Qt::darkGray;
p.setColor(QPalette::Highlight, hc);
}
private:
QTableView * _tableView;
};
3) Also add the following code, just above the "QString newStr = QString("^[%1].*").arg(str);" line:
tableView->setItemDelegate(new TestItemDelegate(tableView));
tableView->verticalHeader()->setDefaultSectionSize(15);
4) Compile and run the program
5) Add three addresses starting with the same letter (so that the visible table has three rows in it)
6) Click on a cell in the table
7) Use the arrow keys to move the current-focus-cell around the table. (The TestItemDelegate will cause the current cell to show up in with a lighter cyan background color than the other cells in the same row).
8) Note that in row #2 and row #3, everything works fine, but when you are in row #1 and press the left and right arrow keys, the background colors of the cells do not update as expected. That is the bug.
More information
Below is a link to a screen-capture video of me reproducing the bug on my Mac. Be sure to play it back full-screen so you can read the text. Note that I put a printf() into QAbstractItemView::update() (in the window at the bottom left of the video) showing where I think the problem is in the Qt codebase. The program's stdout output shows the bug: QAbstractItemView:update() is doing intersection-tests between two rectangles that are not in the same co-ordinate system, the result being that it thinks the top row of the table is not visible and thus suppresses updates to it.
http://www.screentoaster.com/watch/stUk9XRkFIR1xaQ1RaWlhYXl5R