Just like the docs say:How can I update that part of QScrollBar when scrolling?
Which is just the same as the code example you posted.Use viewport->update() to update the contents of the viewport instead of update() as all painting operations take place on the viewport.
Doesn't it work?
Did you try setViewportMargins()?There is a way for set that margin to zero pixel?
Bookmarks