[QScintilla] Scrolling content of QScintilla viewport
Phil Thompson
phil at riverbankcomputing.com
Fri Jul 17 16:59:46 BST 2015
On 16/07/2015 6:50 pm, fulcrumusa at aim.com wrote:
> Hi,
>
>
> I am trying to get QScintilla widget to scroll the content so the
> selected line is in the middle
> of the viewport. I am using Python 2.7.10, PyQt4-4.11.3, and
> QScintilla 2.8.4. I've tried the following:
>
>
>
> self.editor = Qsci.QsciScintilla()
> self.lexer = Qsci.QsciLexerCPP()
> self.file = QFile(filename)
> if not self.file.open(QIODevice.ReadOnly):
> print "Error opening file", filename
> return
> self.editor.read(self.file)
> size = self.editor.viewport().frameSize()
> font = self.lexer.defaultFont(0)
> fontmetrics = QFontMetrics(font)
> num_lines = size.height() / fontmetrics.lineSpacing()
> self.editor.scrollContentsBy(0, (num_lines / 2) *
> fontmetrics.lineSpacing())
> self.editor.setFocus()
>
>
> self.editor.setSelection(line - 1, 0, line, 0)
>
>
>
> But that does not work. It appears that the content is scrolled so the
> selected line is just below
> the viewable area of the document - if I scroll down a couple of
> lines, the selected line is in view.
>
>
> Is there a way that I can do that? Thank you for the help.
You could try the low-level SCI_LINESCROLL...
http://www.scintilla.org/ScintillaDoc.html#SCI_LINESCROLL
Phil
More information about the QScintilla
mailing list