<?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[How to make QRangeModel in Python PySide6 with pure strings?]]></title><description><![CDATA[<p dir="auto">Hello!<br />
I am trying to use QRangeModel to easily create a many-row, 2-column model based off some data<br />
However, it really does not like strings. Here are a few examples of outputs.</p>
<pre><code>table = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
]

m = QRangeModel(table)
</code></pre>
<p dir="auto">This prints <code>2</code> rows, via <code>.rowCount()</code> and <code>4</code> columns, via <code>.columnCount()</code> as expected.</p>
<pre><code>table = [
    ["foo", "bar", 3, 4],
    ["hi", "bye", 7, 8],
]

m = QRangeModel(table)
</code></pre>
<p dir="auto">Likewise, this prints <code>2</code> rows and <code>4</code> columns.</p>
<pre><code>table = [
    ["foo", "bar", "rab", "oof"],
    ["hi", "bye", "eyb", "ih"],
]

m = QRangeModel(table)
</code></pre>
<p dir="auto">However, this prints <code>2</code> rows and <code>1</code> column. However, there's clearly 4 columns here? Getting the data shows that it has created: <code>fbro</code> and <code>hbei</code> as the two items in the one column. It pulled the first character from each string, and created a new one from it.</p>
<p dir="auto">How on earth do I make a QRangeModel with data of pure strings??</p>
]]></description><link>https://forum.qt.io/topic/164994/how-to-make-qrangemodel-in-python-pyside6-with-pure-strings</link><generator>RSS for Node</generator><lastBuildDate>Mon, 14 Sep 2026 22:36:36 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164994.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 10 Aug 2026 20:11:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to make QRangeModel in Python PySide6 with pure strings? on Tue, 25 Aug 2026 07:26:58 GMT]]></title><description><![CDATA[<p dir="auto">Support for string tables has been added in 6.12.</p>
]]></description><link>https://forum.qt.io/post/839849</link><guid isPermaLink="true">https://forum.qt.io/post/839849</guid><dc:creator><![CDATA[friedemannkleint]]></dc:creator><pubDate>Tue, 25 Aug 2026 07:26:58 GMT</pubDate></item><item><title><![CDATA[Reply to How to make QRangeModel in Python PySide6 with pure strings? on Wed, 12 Aug 2026 07:08:44 GMT]]></title><description><![CDATA[<p dir="auto">The <a href="https://doc.qt.io/qtforpython-6/examples/example_widgets_itemviews_rangemodel.html#example-widgets-itemviews-rangemodel" target="_blank" rel="noopener noreferrer nofollow ugc">QRangeModel example</a> shows what currently works. The main use case for QRangeModel for us was to get numpy data into a graphs view conveniently; string tables work do not work (yet). QAbstractTableModel would be better suited for this.</p>
]]></description><link>https://forum.qt.io/post/839666</link><guid isPermaLink="true">https://forum.qt.io/post/839666</guid><dc:creator><![CDATA[friedemannkleint]]></dc:creator><pubDate>Wed, 12 Aug 2026 07:08:44 GMT</pubDate></item><item><title><![CDATA[Reply to How to make QRangeModel in Python PySide6 with pure strings? on Tue, 11 Aug 2026 15:30:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jayrickaby">@<bdi>jayrickaby</bdi></a> said in <a href="/post/839658">How to make QRangeModel in Python PySide6 with pure strings?</a>:</p>
<blockquote>
<p dir="auto">With your example, it was printing 2 rows and 1 column for me. Try putting the QRangeModel now into a TableView or TreeView's model. You can see that the data is weirdly smushed into that one column.</p>
</blockquote>
<p dir="auto">I don't think it will be wrong for me as mine reports 4 columns where yours reports 1.  Your problem for that is at the model side, for whatever reason.  My suggestion is that this is working "oddly" in PySide6 and explicitly rejected in PyQt6, so all bets are off.  And we don't know what platform/Qt/PySide/Python version you are using, may be different from mine.</p>
]]></description><link>https://forum.qt.io/post/839662</link><guid isPermaLink="true">https://forum.qt.io/post/839662</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 11 Aug 2026 15:30:02 GMT</pubDate></item><item><title><![CDATA[Reply to How to make QRangeModel in Python PySide6 with pure strings? on Tue, 11 Aug 2026 11:49:37 GMT]]></title><description><![CDATA[<p dir="auto">With your example, it was printing 2 rows and 1 column for me. Try putting the QRangeModel now into a TableView or TreeView's model. You can see that the data is weirdly smushed into that one column. To be fair, I decided to just start porting my backend to C++, but I will look into QRangeModelAdapter in the future because I hate models and want to deal with them easily while in Python</p>
]]></description><link>https://forum.qt.io/post/839658</link><guid isPermaLink="true">https://forum.qt.io/post/839658</guid><dc:creator><![CDATA[jayrickaby]]></dc:creator><pubDate>Tue, 11 Aug 2026 11:49:37 GMT</pubDate></item><item><title><![CDATA[Reply to How to make QRangeModel in Python PySide6 with pure strings? on Tue, 11 Aug 2026 08:21:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jayrickaby">@<bdi>jayrickaby</bdi></a><br />
Testing following code with Qt 6.10.2:</p>
<pre><code>import sys
from PySide6.QtCore import QCoreApplication, QRangeModel
#from PyQt6.QtCore import QCoreApplication, QRangeModel

if __name__ == '__main__':
    app = QCoreApplication(sys.argv)
    table = [
        ["foo", "bar", "rab", "oof"],
        ["hi", "bye", "eyb", "ih"],
        #[1, 2, 3, 4],
        #[5, 6, 7, 8],
    ]
    m = QRangeModel(table)
    print(m.rowCount(), m.columnCount())
    print(m.data(m.index(0, 0)))
    print(m.data(m.index(1, 0)))
    # sys.exit(app.exec_())
</code></pre>
<p dir="auto">Firstly: I do not get your</p>
<blockquote>
<p dir="auto">Getting the data shows that it has created: fbro and hbei as the two items in the one column. It pulled the first character from each string, and created a new one from it.</p>
</blockquote>
<p dir="auto">Instead I get a single column with the full list <code>["foo", "bar", "rab", "oof"]</code> in it.  As I would expect.  With the number lists instead I do get 4 columns.  Maybe something to do with <code>QStringList</code> being a known type/<code>QVariant</code>-convertible while <code>QList&lt;int&gt;</code> is not?</p>
<p dir="auto">However, in any case I do not see how your lists-as-elements make any sense for your attempted use of <code>QRangeModel</code> here?  Tellingly, if I change to use <strong>PyQt6</strong> instead of <strong>PySide6</strong> <em>both</em> string-list and number-list cases generated error:</p>
<pre><code>TypeError: QRangeModel(range: QPyAbstractRange|None, parent: QObject|None = None): argument 1 has unexpected type 'list'
</code></pre>
<p dir="auto">So no code with list-elements is acceptable as a <code>QRangeModel</code> to PyQt, which is actually what I would expect, I think (not quite sure how <code>QRangeModel</code> is supposed to be used).</p>
<p dir="auto">The fact that PyQt rejects this attempt while PySide accepts it but then behaves oddly "sounds an alarm bell".</p>
<p dir="auto">You may need to explain exactly what you are trying to achieve with these "range-models-of-list-elements".</p>
<p dir="auto">It is possible that a new class introduced apparently at Qt 6.11, <a href="https://doc.qt.io/qt-6/qrangemodeladapter.html" target="_blank" rel="noopener noreferrer nofollow ugc">QRangeModelAdapter Class</a>, may be relevant to you.  Googling delivers:</p>
<blockquote>
<p dir="auto">QRangeModelAdapter is a component introduced as a technology preview in Qt 6.11 designed to simplify how you modify data structures linked to a QRangeModel. It provides a bridge that allows you to interact directly with an underlying sequential data structure (like a Python list or a NumPy array) using standard, convenient methods without manually dealing with boilerplate QAbstractItemModel conventions, QModelIndex tracking, or QVariant wrapping</p>
</blockquote>
<p dir="auto">Behaviour is all tied up with C++ ranges, I don't know whether that may have a problem from Python.</p>
]]></description><link>https://forum.qt.io/post/839654</link><guid isPermaLink="true">https://forum.qt.io/post/839654</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 11 Aug 2026 08:21:13 GMT</pubDate></item></channel></rss>