<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Signal when QTableWidget scroll hits the end of the table?]]></title><description><![CDATA[<p dir="auto">I have a table with which I've populated some Mariadb results. When scrolling, as I go down the table I would like to trigger a search for the next set of results (rather than having all results being reported at once - with some large database tables you could end up with an unruly amount of data coming back for some queries!).</p>
<p dir="auto">It is possible to detect when the user scrolling makes the table hit the end? Both with the mouse scroll wheel and dragging the table down using he scroll bar?</p>
<p dir="auto">Thanks.</p>
]]></description><link>https://forum.qt.io/topic/164498/signal-when-qtablewidget-scroll-hits-the-end-of-the-table</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 01:27:53 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164498.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 30 Mar 2026 08:46:39 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Signal when QTableWidget scroll hits the end of the table? on Tue, 31 Mar 2026 17:58:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jeremy_k">@<bdi>jeremy_k</bdi></a> Oh, wow, I'm sorry!  I understand you now, it's already set to do that!  Didn't know, thanks.</p>
]]></description><link>https://forum.qt.io/post/837463</link><guid isPermaLink="true">https://forum.qt.io/post/837463</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 31 Mar 2026 17:58:14 GMT</pubDate></item><item><title><![CDATA[Reply to Signal when QTableWidget scroll hits the end of the table? on Tue, 31 Mar 2026 17:29:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/837446">Signal when QTableWidget scroll hits the end of the table?</a>:</p>
<blockquote>
<p dir="auto">I pointed the user at <code>fetchMore()</code> for the data, the bit he has to "roll" is the recognition of when to call it, such as your code.</p>
</blockquote>
<p dir="auto">That's not my code. It's in the implementation of QAbstractItemView.</p>
]]></description><link>https://forum.qt.io/post/837462</link><guid isPermaLink="true">https://forum.qt.io/post/837462</guid><dc:creator><![CDATA[jeremy_k]]></dc:creator><pubDate>Tue, 31 Mar 2026 17:29:48 GMT</pubDate></item><item><title><![CDATA[Reply to Signal when QTableWidget scroll hits the end of the table? on Tue, 31 Mar 2026 08:37:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jeremy_k">@<bdi>jeremy_k</bdi></a> said in <a href="/post/837441">Signal when QTableWidget scroll hits the end of the table?</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dibosco">@<bdi>DiBosco</bdi></a><br />
Well, there is not actually anything "built in" for this. You have to roll something yourself.</p>
<p dir="auto">This is the purpose of QAbstractItemModel::canFetchMore(), coupled with fetchMore().</p>
</blockquote>
<p dir="auto">The "nothing actually built in" referred to no in-built facility to recognise a scroll to the bottom of a <code>QTableWidget</code> causing some kind of call to fetch more rows.  I pointed the user at <code>fetchMore()</code> for the data, the bit he has to "roll" is the recognition of when to call it, such as your code.</p>
]]></description><link>https://forum.qt.io/post/837446</link><guid isPermaLink="true">https://forum.qt.io/post/837446</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 31 Mar 2026 08:37:31 GMT</pubDate></item><item><title><![CDATA[Reply to Signal when QTableWidget scroll hits the end of the table? on Tue, 31 Mar 2026 03:09:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/837424">Signal when QTableWidget scroll hits the end of the table?</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dibosco">@<bdi>DiBosco</bdi></a><br />
Well, there is not actually anything "built in" for this.  You have to roll something yourself.</p>
</blockquote>
<p dir="auto">This is the purpose of <a href="https://doc.qt.io/qt-6/qabstractitemmodel.html#canFetchMore" target="_blank" rel="noopener noreferrer nofollow ugc">QAbstractItemModel::canFetchMore()</a>, coupled with fetchMore().</p>
<p dir="auto"><a href="https://codebrowser.dev/qt6/qtbase/src/widgets/itemviews/qabstractitemview.cpp.html#_ZN17QAbstractItemView29verticalScrollbarValueChangedEi" target="_blank" rel="noopener noreferrer nofollow ugc">qabstractitemview.cpp</a>:</p>
<pre><code>void QAbstractItemView::verticalScrollbarValueChanged(int value)
{
    Q_D(QAbstractItemView);
    if (verticalScrollBar()-&gt;maximum() == value &amp;&amp; d-&gt;model-&gt;canFetchMore(d-&gt;root))
        d-&gt;model-&gt;fetchMore(d-&gt;root);
</code></pre>
<p dir="auto">There's even an example: <a href="https://doc.qt.io/qt-6/qtwidgets-itemviews-fetchmore-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">Fetch More Example</a></p>
]]></description><link>https://forum.qt.io/post/837441</link><guid isPermaLink="true">https://forum.qt.io/post/837441</guid><dc:creator><![CDATA[jeremy_k]]></dc:creator><pubDate>Tue, 31 Mar 2026 03:09:50 GMT</pubDate></item><item><title><![CDATA[Reply to Signal when QTableWidget scroll hits the end of the table? on Mon, 30 Mar 2026 12:44:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/j.hilk">@<bdi>J.Hilk</bdi></a><br />
Ah, right, without subclassing.  Do you get the <code>QScrollBar::valueChanged()</code> if it's from the wheel?  You probably do, else you have to subclass to catch the wheel I believe.</p>
<p dir="auto">At the moment the OP is apparently using a <code>QTableWidget</code>, with its own standard item model data which has to be copied to etc. from some MariaDB SQL query.  I advised they would be better off changing to <code>QTableView</code> + <code>QSql...Model...</code> calls to manage fetching chunks from the database better.  Then they can use the <code>fetchMore()</code> rather than some new query to continue.</p>
]]></description><link>https://forum.qt.io/post/837431</link><guid isPermaLink="true">https://forum.qt.io/post/837431</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 30 Mar 2026 12:44:35 GMT</pubDate></item><item><title><![CDATA[Reply to Signal when QTableWidget scroll hits the end of the table? on Mon, 30 Mar 2026 11:26:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> suggestion is the better way to do it for sure, but for your current use case, simply listen to the valueChanged signal of your QScrollbar, something like:</p>
<pre><code>connect(ui-&gt;tableView-&gt;verticalScrollBar(), &amp;QScrollBar::valueChanged,
        this, &amp;MyWidget::onScrollChanged);
</code></pre>
<p dir="auto">and than simply fetch more, when reaching the end, or near the ende, in case you want to start loading a little bit earlier for a smoother experience:</p>
<pre><code>void MyWidget::onScrollChanged(int value)
{
    QScrollBar const * const bar = ui-&gt;tableView-&gt;verticalScrollBar();
    if (value &gt;= bar-&gt;maximum() - 50) {
        fetchNextPage();
    }
}
</code></pre>
]]></description><link>https://forum.qt.io/post/837428</link><guid isPermaLink="true">https://forum.qt.io/post/837428</guid><dc:creator><![CDATA[J.Hilk]]></dc:creator><pubDate>Mon, 30 Mar 2026 11:26:51 GMT</pubDate></item><item><title><![CDATA[Reply to Signal when QTableWidget scroll hits the end of the table? on Mon, 30 Mar 2026 11:30:22 GMT]]></title><description><![CDATA[<p dir="auto">Hi Jon, thanks for that.</p>
<p dir="auto">Couple of points/follow-ups if I may.</p>
<p dir="auto">I wasn't aware of QSqlTableModel, QSqlQueryModel etc. I have been using QSqlQuery to carry out my mariadb query and putting results into a QStringList vector, then taking that data and putting it into a QTableWidget in the order I want it. It works beautifully and is really fast, even when I return, say, a thousand records with multiple columns.</p>
<p dir="auto">Are you basically saying this method is poor?</p>
<p dir="auto">I do have to be careful with insertRow, setRowCount,clearContents etc etc when using a QTableWidget, but as long as I careful it all works a treat.</p>
<p dir="auto">Now, the caveat as I said when you answered my DLL query a couple of weeks ago, I am strictly speaking an embedded software engineer, and although I am getting reasonably proficient in C++ and Qt, I am very happy to admit I am absolutely no expert, I might well be doing this in the wrong way. Or at least not the best way!</p>
]]></description><link>https://forum.qt.io/post/837427</link><guid isPermaLink="true">https://forum.qt.io/post/837427</guid><dc:creator><![CDATA[DiBosco]]></dc:creator><pubDate>Mon, 30 Mar 2026 11:30:22 GMT</pubDate></item><item><title><![CDATA[Reply to Signal when QTableWidget scroll hits the end of the table? on Mon, 30 Mar 2026 09:46:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dibosco">@<bdi>DiBosco</bdi></a><br />
Well, there is not actually anything "built in" for this.  You have to roll something yourself.</p>
<p dir="auto">You can either intercept the scrollbar/mouse events, check for "reached or near the the bottom" and <code>fetchMore()</code> when it hits there.  Or what some people do is have the <code>rowCount()</code> report <em>more</em> than the actual number of rows, so that technically you can scroll <em>beyond</em> the last row, and detect that and <code>fetchMore()</code> then.  Variations on a theme.</p>
<p dir="auto"><code>QTableWidget</code>, as opposed to <code>QTableView</code>, may present some difficulties fiddling with its <code>rowCount()</code> as the model is built in and kind of hidden for subclassing.  But in any case <code>QTableWidget</code> is quite the wrong widget for querying a SQL database like MariaDB, especially if a large number of rows/columns.  Grossly inefficient.  You should change to <code>QTableView</code> plus <code>QSqlQueryModel</code> or <code>QSqlTableModel</code>.</p>
<blockquote>
<p dir="auto">as I go down the table I would like to trigger a search for the next set of results (rather than having all results being reported at once - with some large database tables you could end up with an unruly amount of data coming back for some queries!).</p>
</blockquote>
<p dir="auto">Be aware that so long as you are using the <code>QSql...Model...</code> calls if there are a million matching rows it does <em>not</em> read all those million rows immediately!  In fact, you should find that it (Qt) is hard-coded to fetch 256 rows at a time.  The rest are still at the server while the query is active.  You use <a href="https://doc.qt.io/qt-6/qsqlquerymodel.html#fetchMore" target="_blank" rel="noopener noreferrer nofollow ugc">void QSqlQueryModel::fetchMore()</a> to fetch the next batch(es) of 256.  This is more efficient than some sort of "issue a new query to pick up where you got to".</p>
]]></description><link>https://forum.qt.io/post/837424</link><guid isPermaLink="true">https://forum.qt.io/post/837424</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 30 Mar 2026 09:46:12 GMT</pubDate></item></channel></rss>