[QScintilla] Scrolling content of QScintilla viewport

Phil Thompson phil at riverbankcomputing.com
Tue Jul 21 10:41:14 BST 2015


On 18/07/2015 12:54 am, fulcrumusa at aim.com wrote:
>> You could try the low level SCI_LINESCROLL...
>> 
>> 
> http://www.scintilla.org/ScintillaDoc.html#SCI_LINESCROLL
> 
> 
> Hi Phil,
> 
> Thank you
> for the suggestion. I did try that (after digging through the
> QScintilla code because SF.net is down :)).

The Scintilla docs are in the source package.

> While I can scroll the text, I am getting somewhat
> inconsistent behavior from QScintilla editor even without scrolling.
> 
> I have the following code now:
> 
>         self.file = QFile(filename)
>         if not self.file.open(QIODevice.ReadOnly):
>             print "Error opening file", filename
> 
>         self.editor.read(self.file)
>         size = self.editor.viewport().frameSize()
>         font = self.lexer.defaultFont(0)
> 
>         fontmetrics = QFontMetrics(font)
>         print "viewport size %u, line spacing: %u" % \
>               (size.height(), fontmetrics.lineSpacing())
> 
>         num_lines = size.height() / fontmetrics.lineSpacing()
>         print "number of lines on screen %d" % num_lines
>         scroll_by_lines = (num_lines / 2)
> 
>         self.editor.setFocus()
> 
>         self.editor.SendScintilla(Qsci.QsciScintilla.SCI_GOTOLINE, 
> line)
> 
>         #self.editor.setSelection(line - 1, 0, line, 0)
>         #self.editor.setSelectionBackgroundColor(QColor("#cccccc"))
>         self.editor.recolor()
>         print "scrolling by %d lines" % scroll_by_lines
>         #self.editor.SendScintilla(Qsci.QsciScintilla.SCI_LINESCROLL, 
> 0,
>         #                                   scroll_by_lines)
> 
> As you can see, I use the raw SCI_GOTOLINE command to put the
> editor at the desired line. However, the line is not always visible as 
> the
> documentation says it should be. If the viewport is small, the line is 
> just
> below the visible area.
> If it is large, the target line is always 6 lines from the bottom of
> the viewable
> area.
> 
> Furthermore, regardless of how big I resize the editor widget to,
> self.editor.viewport().frameSize() always returns the same size.
> 
> How does QScintilla determine the size of the viawable are?

It's all related to the manipulation of the scrollbars. See the 
scrollbar related functions in ScintillaQt.cpp.

Phil


More information about the QScintilla mailing list