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



  • 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?



  • I don't believe nobody experienced this issue. :(


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.