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