<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="Generator" content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
p.Code, li.Code, div.Code
{mso-style-name:Code;
mso-style-priority:99;
mso-style-link:"Code Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:9.0pt;
font-family:"Courier New";}
span.CodeChar
{mso-style-name:"Code Char";
mso-style-priority:99;
mso-style-link:Code;
font-family:"Courier New";}
p.Reply, li.Reply, div.Reply
{mso-style-name:Reply;
mso-style-link:"Reply Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";
color:#1F497D;}
span.ReplyChar
{mso-style-name:"Reply Char";
mso-style-link:Reply;
color:#1F497D;
mso-fareast-language:EN-CA;}
span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";
mso-fareast-language:EN-CA;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style></head><body lang="EN-CA" link="blue" vlink="purple"><div class="WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I fixed it by setting the scroll mode of the QTableView to per pixel instead of per item (per item is the default): </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">self.setVerticalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel)</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">I looked into the C++ of QTableView and found that in the scrollContentsBy method, if scroll mode was per item, when the scroll bar value was equal to the maximum of the scroll bar it would call setOffsetToLastSection() of the header as opposed to setting the offset of the header to be the value of the scroll bar. This causes the “snapping” effect I described when the scroll bar got to the very end. The C++ for QTableView can be seen as follows (this is for horizontal but it is the same for vertical):</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> int oldOffset = d->horizontalHeader->offset();</span></p><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> if (horizontalScrollBar()->value() == horizontalScrollBar()->maximum())</span></b></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> d->horizontalHeader->setOffsetToLastSection();</span></p><p class="MsoNormal">
<span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> else</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> d->horizontalHeader->setOffsetToSectionPosition(horizontalScrollBar()->value());</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> int newOffset = d->horizontalHeader->offset();</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">} else {</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> d->horizontalHeader->setOffset(horizontalScrollBar()->value());</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">}</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Thanks for your help Paul, it is greatly appreciated.</span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p>
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Paul Du Bois [mailto:<a href="mailto:dubois@doublefine.com">dubois@doublefine.com</a>] <br>
<b>Sent:</b> August-29-13 4:29 PM<br><b>To:</b> Mark Mordeca<br><b>Cc:</b> <a href="mailto:pyqt@riverbankcomputing.com">pyqt@riverbankcomputing.com</a><br><b>Subject:</b> Re: [PyQt] Scroll QTableView beyond last column/row</span></p>
<p class="MsoNormal"> </p><div><div><p class="MsoNormal"><span style="color:#003300">Hmmm. I haven't seen that behavior, but it might be specific to particular Qt versions (I'm on a slightly old one). I think the general idea of only futzing with the scrollarea/scrollbar is pretty sound, though. You might get some traction on that bug by checking to see if it's the scrollbar that's getting its range changed (or its value changed) behind your back somehow, or if someone's moving the view independently of the scrollbar.</span></p>
</div><div><p class="MsoNormal"><span style="color:#003300"> </span></p></div><div><p class="MsoNormal"><span style="color:#003300">p</span></p></div></div><div><p class="MsoNormal" style="margin-bottom:12.0pt"> </p><div>
<p class="MsoNormal">On Thu, Aug 29, 2013 at 5:39 AM, Mark Mordeca <<a href="mailto:mark.mordeca@prosensus.ca" target="_blank">mark.mordeca@prosensus.ca</a>> wrote:</p><div><div><p class="MsoNormal" style><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Thanks, this is pretty much provides the behaviour I want, however there is one oddity with it. It allows me to successfully scroll past the last row, but at a certain point I will be able to move the scroll bar to the very end which causes the entire table to “snap” back to the bottom. Did you find a way to avoid this?</span></p>
<p class="MsoNormal" style><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p><p class="MsoNormal" style><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d">Appreciate your help.</span></p>
<p class="MsoNormal" style><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d"> </span></p><p class="MsoNormal" style><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Paul Du Bois [mailto:<a href="mailto:dubois@doublefine.com" target="_blank">dubois@doublefine.com</a>] <br>
<b>Sent:</b> August-28-13 4:34 PM<br><b>To:</b> Mark Mordeca<br><b>Cc:</b> <a href="mailto:pyqt@riverbankcomputing.com" target="_blank">pyqt@riverbankcomputing.com</a><br><b>Subject:</b> Re: [PyQt] Scroll QTableView beyond last column/row</span></p>
<p class="MsoNormal" style> </p><div><div><p class="MsoNormal" style><span style="color:#003300">I do this:</span></p></div><div><p class="MsoNormal" style><span style="color:#003300"> </span></p></div><div><div><p class="MsoNormal" style>
<span style="font-family:"Courier New";color:#003300"> # somewhere in init</span></p></div><div><p class="MsoNormal" style><span style="font-family:"Courier New";color:#003300"> self._last_vsb_height = None</span></p>
</div><div><p class="MsoNormal" style><span style="font-family:"Courier New";color:#003300"> self.verticalScrollBar().rangeChanged[int,int].connect(self._on_range_changed)</span></p></div><div><p class="MsoNormal" style>
</p></div><div><p class="MsoNormal" style><span style="font-family:"Courier New";color:#003300"> def _on_range_changed(self, min, max):</span></p></div><div><p class="MsoNormal" style><span style="font-family:"Courier New";color:#003300"> # Try to prevent infinite recursion</span></p>
</div><div><p class="MsoNormal" style><span style="font-family:"Courier New";color:#003300"> # Count is in rows</span></p></div><div><p class="MsoNormal" style><span style="font-family:"Courier New";color:#003300"> if max != self._last_vsb_height: </span></p>
</div><div><p class="MsoNormal" style><span style="font-family:"Courier New";color:#003300"> sender = self.verticalScrollBar()</span></p></div><div><p class="MsoNormal" style><span style="font-family:"Courier New";color:#003300"> self._last_vsb_height = max + 20</span></p>
</div><div><p class="MsoNormal" style><span style="font-family:"Courier New";color:#003300"> sender.setRange(min, self._last_vsb_height)</span></p></div><div><p class="MsoNormal" style><span style="color:#003300"> </span></p>
</div></div></div><div><p class="MsoNormal" style="margin-bottom:12.0pt"> </p><div><p class="MsoNormal" style>On Wed, Aug 28, 2013 at 12:28 PM, Mark Mordeca <<a href="mailto:mark.mordeca@prosensus.ca" target="_blank">mark.mordeca@prosensus.ca</a>> wrote:</p>
<div><div><p class="MsoNormal" style>Greetings,</p><p class="MsoNormal" style> </p><p class="MsoNormal" style>I have a simple QTableView connected to an QAbstractTableModel. For the purposes of my question, let’s assume that these are the most basic you can have in order to get a table with data in it.</p>
<p class="MsoNormal" style> </p><p class="MsoNormal" style>Default behaviour is that you can scroll the table so that the last column/row becomes visible, but no further. I would like to be able to scroll the table <i>past</i> the last row/column, i.e. I want to be able to continue to click right on the horizontal scroll bar even though I have reached the last column, thereby making the last column continue to shift left in the table revealing “empty space” in the TableView. </p>
<p class="MsoNormal" style> </p><p class="MsoNormal" style>I have been unsuccessful in trying to find a way and hoped that someone here had a way to do this or a suggestion as to how.</p><p class="MsoNormal" style> </p><p class="MsoNormal" style>
Thank you,</p><p class="MsoNormal" style>Mark </p><p class="MsoNormal" style> </p></div></div><p class="MsoNormal" style><br>_______________________________________________<br>PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></p></div><p class="MsoNormal" style> </p></div></div></div></div><p class="MsoNormal">
</p></div></div></body></html>