<font color='black' size='2' face='arial'><font face="arial" style="color: black; font-family: arial; font-size: small; background-color: rgb(255, 255, 255);"><span style="font-size: 10pt;">Hi, </span></font>
<div style="color: black; font-family: arial; font-size: 10pt;"><br>
</div>

<div style="color: black; font-family: arial; font-size: 10pt;"><font face="arial" style="font-size: small; background-color: rgb(255, 255, 255);"><span style="font-size: 10pt;">I am trying to get QScintilla widget to scroll the content so the selected line is in the middle</span></font></div>

<div><font face="arial" style="color: black; font-family: arial; font-size: small; background-color: rgb(255, 255, 255);"><span style="font-size: 10pt;">of the viewport. I am using Python 2.7.10, PyQt4-4.11.3, and QScintilla 2.8.4. I've tried the following:</span></font><font face="arial"><span style="font-size: small; background-color: rgb(255, 255, 255);"></span></font>
<div style="color: black; font-family: arial; font-size: 10pt; background-color: rgb(255, 255, 255);"><br>
</div>

<div style="background-color: rgb(255, 255, 255);">
<div><font face="arial" size="2"><span class="Apple-tab-span" style="white-space:pre">        </span>self.editor = Qsci.QsciScintilla()</font></div>

<div><font face="arial" size="2">        self.lexer = Qsci.QsciLexerCPP()</font></div>

<div><font face="arial" style="color: black; font-family: arial; font-size: small;">        </font><font face="arial" size="2">self.file = QFile(filename)</font></div>

<div><font face="arial" size="2">        if not self.file.open(QIODevice.ReadOnly):</font></div>

<div><font face="arial" size="2">            print "Error opening file", filename</font></div>

<div><font face="arial" size="2"><span class="Apple-tab-span" style="white-space:pre">        </span>    return</font></div>

<div><font face="arial" style="color: black; font-family: arial; font-size: small;"><span class="Apple-tab-span" style="white-space:pre">     </span>self.editor.read(self.file)</font></div>

<div style="color: black; font-family: arial; font-size: small;"><font face="arial">        size = self.editor.viewport().frameSize()</font></div>

<div style="color: black; font-family: arial; font-size: small;"><font face="arial">        font = self.lexer.defaultFont(0)</font></div>

<div style="color: black; font-family: arial; font-size: small;"><font face="arial">        fontmetrics = QFontMetrics(font)</font></div>

<div style="color: black; font-family: arial; font-size: small;"><font face="arial">        num_lines = size.height() / fontmetrics.lineSpacing()</font></div>

<div style="color: black; font-family: arial; font-size: small;"><font face="arial">        self.editor.scrollContentsBy(0, (num_lines / 2) * fontmetrics.lineSpacing())</font></div>

<div style="color: black; font-family: arial; font-size: small;"><font face="arial">        self.editor.setFocus()</font></div>

<div style="color: black; font-family: arial; font-size: small;"><font face="arial"><br>
</font></div>

<div style="color: black; font-family: arial; font-size: small;"><font face="arial">        self.editor.setSelection(line - 1, 0, line, 0)</font></div>
</div>

<div style="color: black; font-family: arial; font-size: small; background-color: rgb(255, 255, 255);"><font face="arial"><br>
</font></div>

<div style="color: black; font-family: arial; font-size: small; background-color: rgb(255, 255, 255);"><font face="arial">But that does not work. It appears that the content is scrolled so the selected line is just below</font></div>

<div style="color: black; font-family: arial; font-size: small; background-color: rgb(255, 255, 255);"><font face="arial">the viewable area of the document - if I scroll down a couple of lines, the selected line is in view.</font></div>

<div style="color: black; font-family: arial; font-size: small; background-color: rgb(255, 255, 255);"><font face="arial"><br>
</font></div>

<div style="color: black; font-family: arial; font-size: small; background-color: rgb(255, 255, 255);"><font face="arial">Is there a way that I can do that? Thank you for the help.</font></div>

<div style="color: black; font-family: arial; font-size: small; background-color: rgb(255, 255, 255);"><font face="arial"><br>
</font></div>

<div style="color: black; font-family: arial; font-size: small; background-color: rgb(255, 255, 255);"><font face="arial">- Mitko</font></div>
</div>
</font>