How do I tell if a QPlainTextEdit has scrolled?

106 Views Asked by At

There is a well know bug (feature?) that valueChanged signals are blocked some of the time for a scrollbar associated with a QTpainTextEdit, so I figured I'd override the scrollContentsBy() virtual function and notice scrolling that way. But scrollContentsBy is also sometimes not called. So how the devil can a program reliably notice that a QPlainTextEdit was scrolled?

1

There are 1 best solutions below

2
On

You could check the current content offset with contentOffset() when you need to know whether scrolling has been changed. It's a protected method, so you need to subclass QPlainTextEdit to call it. One caveat is that if the content is smaller than the viewport, it will give back (0,0) even if the content was moved within the viewport, so at the end it depends on your definition of scrolling, but you can implement some custom logic for it, depending on your requirements.