[Solved] QListView smears and blanks text



  • I have a QListView to maintain. It gets populated with some text, and also (I think) some lines that are drawn using some custom code; there exists a QStyledItemDelegate that is involved, and it has some custom paint functions.

    Anyway, scrolling right with the mouse causes the words to "smear", and then scrolling back reveals a big blank space where there used to be words, and then waiting and not touching anything for several seconds makes everything better.

    I'm stumped as to what causes this. Does anyone have any suggestions on what to look for?


  • Moderators

    i would look for the delegates paint() and sizeHint() method first



  • Aha. Ripping out the overridden sizeHint and letting it just always call the QStyledItemDelegate::sizeHint() function made the appearance quite different. Broken, but different, so maybe that's where I need to investigate.



  • Huh. Another listview right next to it showing more or less that same thing uses an identical delegate class, but suffers no smearing.


  • Moderators

    [quote author="Moschops" date="1386337502"]Aha. Ripping out the overridden sizeHint and letting it just always call the QStyledItemDelegate::sizeHint() function made the appearance quite different. Broken, but different, so maybe that's where I need to investigate.[/quote]
    the sizeHint() and paint() methods should go hand in hand in most cases. Unless you want to have the default size anyway. I would rather suspect the paint() method, but its not definite.

    [quote author="Moschops" date="1386338090"]Huh. Another listview right next to it showing more or less that same thing uses an identical delegate class, but suffers no smearing.[/quote]
    Define "more or less" :)



  • [quote author="raven-worx" date="1386338435"]
    Define "more or less" :)
    [/quote]

    One of them begins life full of lines of text (each with a little radio button and a couple of horizontal lines), while the other (the "bad" one) has only two. I can, however, move lines from one to the other as much as I like. Giving the "bad" one any set of contents makes no difference (still smears), and giving the good one the same visual set of contents makes no difference (still doesn't smear).

    I'm looking for any obvious differences in how the two instances of the class (which inherits from QStyledItemDelegate) are treated during initialisation etc.



  • Aha. I spotted something in the behaviour I didn't see before.

    What should happen (and what does happen in the good view) is that the layout is effectively fixed; each line is a radio button, then a line of text, and because the view isn't wide enough, you can scroll right to left.

    In the bad view, when you scroll left to right the text smears, and when it eventually updates (which is caused by clicking somewhere else, such as off the application entirely and on the desktop somewhere) it is redrawn, with the text starting at the left-most visible part of the line. So if I scroll right, the text smears, and then what gets drawn is effectively a radio button on the far-left (out of sight), a whole lot of white space (out of sight), and then (beginning at the far left of the visible section) the line of text.

    I don't know what that means but I bet it's significant :p



  • It's this line of code!

    @opt.rect.setLeft(radioButtonWidth + 2 * radioButtonMargin);@

    Taking it out removes the problem entirely (but also draws the text over the top of the little radio button). Right after this, opt (which is a QStyleOptionViewItemV4 object, built using an assignment constructor from a QStyleOptionViewItem) is passed to a QApplication::style::drawControl, which presumably causing the painting to happen.

    I looked up what QStyleOptionViewItemV4::rect.setLeft does, but I think I don't understand the full context, so it still doesn't mean much to me. Still, getting closer!


Log in to reply
 

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