[Interest] QListView and QStyledItemDelegate - item is greater than option rect, problems with painting

Kacper Banasik mattrick at jabster.pl
Fri Apr 6 14:13:51 CEST 2012


Hello! I have a little problem with Qt… The problem is that my
itemdelegate sizeHint() has greater width than listView (and therefore
so is option), so there is a scrollbar. And now I don’t have any idea
how to paint it. I managed to write something like this:


QSize size(sizeHint(option, index));

QRect horizontalRect = option.rect;

horizontalRect.setRight(std::max(option.rect.right(), size.width()));

QRect headerRect = horizontalRect;

headerRect.setTop(headerRect.top()+5);
headerRect.setBottom(headerRect.top()+fm.height());

painter->setFont(font);
painter->drawText(headerRect,headerText, QTextOption(Qt::AlignHCenter));


But the problem is that option.rect.left() is set to 0, so every time
I scroll, text is painted at the beginning of the visible area. To
make it working, I should have (for view scrolled to right edge)
horizontalRect.left() set to -(size.width() – options.rect.width())
and right() to (options.width()). Is there any way to do it? Or at
least a way to get scrollbar scroll between <0; 1> to just calculate
correct left edge of horizontalRect?

-- 
Kacper Banasik



More information about the Interest mailing list