[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Scroll QTableView beyond last column/row
From:       Mark Mordeca <mark.mordeca () prosensus ! ca>
Date:       2013-09-03 12:03:47
Message-ID: 2fc51e356f213e8adf738ec268fe0616 () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I fixed it by setting the scroll mode of the QTableView to per pixel
instead of per item (per item is the default):



self.setVerticalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel)



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):



if (horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {

            int oldOffset = d->horizontalHeader->offset();

*            if (horizontalScrollBar()->value() ==
horizontalScrollBar()->maximum())*

                d->horizontalHeader->setOffsetToLastSection();

            else


d->horizontalHeader->setOffsetToSectionPosition(horizontalScrollBar()->value());

            int newOffset = d->horizontalHeader->offset();

            dx = isRightToLeft() ? newOffset - oldOffset : oldOffset -
newOffset;

} else {

            d->horizontalHeader->setOffset(horizontalScrollBar()->value());

}



Thanks for your help Paul, it is greatly appreciated.



*From:* Paul Du Bois [mailto:dubois@doublefine.com]
*Sent:* August-29-13 4:29 PM
*To:* Mark Mordeca
*Cc:* pyqt@riverbankcomputing.com
*Subject:* Re: [PyQt] Scroll QTableView beyond last column/row



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.



p



On Thu, Aug 29, 2013 at 5:39 AM, Mark Mordeca <mark.mordeca@prosensus.ca>
wrote:

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?



Appreciate your help.



*From:* Paul Du Bois [mailto:dubois@doublefine.com]
*Sent:* August-28-13 4:34 PM
*To:* Mark Mordeca
*Cc:* pyqt@riverbankcomputing.com
*Subject:* Re: [PyQt] Scroll QTableView beyond last column/row



I do this:



        # somewhere in init

        self._last_vsb_height = None


self.verticalScrollBar().rangeChanged[int,int].connect(self._on_range_changed)



    def _on_range_changed(self, min, max):

        # Try to prevent infinite recursion

        # Count is in rows

        if max != self._last_vsb_height:

            sender = self.verticalScrollBar()

            self._last_vsb_height = max + 20

            sender.setRange(min, self._last_vsb_height)





On Wed, Aug 28, 2013 at 12:28 PM, Mark Mordeca <mark.mordeca@prosensus.ca>
wrote:

Greetings,



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.



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 *past* 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.



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.



Thank you,

Mark




_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[Attachment #5 (text/html)]

<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:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span></p><p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:# \
1f497d">self.setVerticalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel)</span></p> \
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span></p><p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span></p><p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">if \
(horizontalScrollMode() == QAbstractItemView::ScrollPerItem) {</span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
int oldOffset = d-&gt;horizontalHeader-&gt;offset();</span></p><p \
class="MsoNormal"><b><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
if (horizontalScrollBar()-&gt;value() == \
horizontalScrollBar()-&gt;maximum())</span></b></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
d-&gt;horizontalHeader-&gt;setOffsetToLastSection();</span></p><p class="MsoNormal"> \
<span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
else</span></p><p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
d-&gt;horizontalHeader-&gt;setOffsetToSectionPosition(horizontalScrollBar()-&gt;value());</span></p>
 <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
int newOffset = d-&gt;horizontalHeader-&gt;offset();</span></p><p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
dx = isRightToLeft() ? newOffset - oldOffset : oldOffset - newOffset;</span></p> <p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">} \
else {</span></p><p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
d-&gt;horizontalHeader-&gt;setOffset(horizontalScrollBar()-&gt;value());</span></p> \
<p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">}</span></p><p \
class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span></p> <p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Thanks \
for your help Paul, it is greatly appreciated.</span></p><p class="MsoNormal"><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span></p> <p class="MsoNormal"><b><span lang="EN-US" \
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span \
lang="EN-US" style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> \
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&#39;t \
seen that behavior, but it might be specific to particular Qt versions (I&#39;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&#39;s the scrollbar that&#39;s getting its range changed (or \
its value changed) behind your back somehow, or if someone&#39;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 &lt;<a href="mailto:mark.mordeca@prosensus.ca" \
target="_blank">mark.mordeca@prosensus.ca</a>&gt; wrote:</p><div><div><p \
class="MsoNormal" style><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;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:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span></p><p class="MsoNormal" style><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d">Appreciate \
your help.</span></p> <p class="MsoNormal" style><span \
style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1f497d"> \
</span></p><p class="MsoNormal" style><b><span lang="EN-US" \
style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span \
lang="EN-US" style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> \
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:&quot;Courier New&quot;;color:#003300">        # somewhere in \
init</span></p></div><div><p class="MsoNormal" style><span \
style="font-family:&quot;Courier New&quot;;color:#003300">        \
self._last_vsb_height = None</span></p> </div><div><p class="MsoNormal" style><span \
style="font-family:&quot;Courier New&quot;;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:&quot;Courier New&quot;;color:#003300">    def \
_on_range_changed(self, min, max):</span></p></div><div><p class="MsoNormal" \
style><span style="font-family:&quot;Courier New&quot;;color:#003300">        # Try \
to prevent infinite recursion</span></p> </div><div><p class="MsoNormal" style><span \
style="font-family:&quot;Courier New&quot;;color:#003300">        # Count is in \
rows</span></p></div><div><p class="MsoNormal" style><span \
style="font-family:&quot;Courier New&quot;;color:#003300">        if max != \
self._last_vsb_height: </span></p> </div><div><p class="MsoNormal" style><span \
style="font-family:&quot;Courier New&quot;;color:#003300">            sender = \
self.verticalScrollBar()</span></p></div><div><p class="MsoNormal" style><span \
style="font-family:&quot;Courier New&quot;;color:#003300">            \
self._last_vsb_height = max + 20</span></p> </div><div><p class="MsoNormal" \
style><span style="font-family:&quot;Courier New&quot;;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 &lt;<a \
href="mailto:mark.mordeca@prosensus.ca" \
target="_blank">mark.mordeca@prosensus.ca</a>&gt; 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>



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic