<?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[&quot;Rotate&quot; TableView]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">So my question is simple. Is there a way to "rotate" a tableView in QML so I could have columns as rows ans rows as columns?</p>
<p dir="auto">For instance, in a normal tableview or listview, it would look like that:</p>
<p dir="auto">name         type          price<br />
apple          fruit          1.50<br />
orange       fruit           2.5<br />
banana      fruit           3.5</p>
<p dir="auto">and I'd like my table like that:</p>
<p dir="auto">name       apple      orange      banana<br />
type         fruit         fruit           fruit<br />
price         1.50        2.5             3.5</p>
<p dir="auto">Is there an easy way to do it with listView or tableVIew? or should I create my own component?</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.qt.io/topic/116791/rotate-tableview</link><generator>RSS for Node</generator><lastBuildDate>Fri, 02 Oct 2026 03:45:31 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/116791.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 Jul 2020 12:43:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to &quot;Rotate&quot; TableView on Thu, 09 Jul 2020 08:55:39 GMT]]></title><description><![CDATA[<p dir="auto">@romain-donze<br />
Then in your research you must have come across  <code>QTransposeProxyModel</code>, for which I have given you the link, which is going to be close to what you need.  So why don't you look at that?  Source code can be seen in <a href="https://code.woboq.org/qt5/qtbase/src/corelib/itemmodels/qtransposeproxymodel.cpp.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://code.woboq.org/qt5/qtbase/src/corelib/itemmodels/qtransposeproxymodel.cpp.html</a>.  Even if you refuse to use a proxy model, you can see from that what sort of thing you will need to do in your own model.</p>
]]></description><link>https://forum.qt.io/post/605719</link><guid isPermaLink="true">https://forum.qt.io/post/605719</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 09 Jul 2020 08:55:39 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Rotate&quot; TableView on Thu, 09 Jul 2020 08:23:56 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">after some research, I was thinking of subclassing QAbstractTableModel and reimplement the <em>data()</em> function to suit my needs.</p>
<p dir="auto">But I can't find any example on how to subclass QAbstractTableModel properly.</p>
<p dir="auto">Then I could simply use MyTableModel in a tableview</p>
]]></description><link>https://forum.qt.io/post/605704</link><guid isPermaLink="true">https://forum.qt.io/post/605704</guid><dc:creator><![CDATA[romain.donze]]></dc:creator><pubDate>Thu, 09 Jul 2020 08:23:56 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Rotate&quot; TableView on Thu, 09 Jul 2020 07:50:16 GMT]]></title><description><![CDATA[<p dir="auto">@romain-donze<br />
I assume <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> was asking about proxy model because of <a href="https://doc-snapshots.qt.io/qt5-dev/qtransposeproxymodel.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc-snapshots.qt.io/qt5-dev/qtransposeproxymodel.html</a></p>
<blockquote>
<p dir="auto">This model will make the rows of the source model become columns of the proxy model and vice-versa.</p>
</blockquote>
<p dir="auto">Take a look at that, either to use directly or possibly to adapt to your case.  The point being, the rows/columns are swapped/rotated at the model stage, for direct use in <code>QTableView</code>, rather than making the view have to deal with it.</p>
]]></description><link>https://forum.qt.io/post/605698</link><guid isPermaLink="true">https://forum.qt.io/post/605698</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 09 Jul 2020 07:50:16 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Rotate&quot; TableView on Thu, 09 Jul 2020 06:01:21 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I am using a C++ model like that</p>
<pre><code>MyCppModel {
    id: myModel
    container: myCppContainer
}
</code></pre>
<p dir="auto">with myCppContainer being something like that</p>
<pre><code>class CppContainer : public QObject
{
public:
    CppContainer(QObject *parent=nullptr);

    // getter
    // setter

private:
    QVecto&lt;MyElement*&gt; m_elements;
}
</code></pre>
<p dir="auto">and MyCppModel being like that</p>
<pre><code>class MyCppModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(CppContainer *container READ getContainer WRITE setContainer NOTIFY sigContainerChanged)
    Q_PROPERTY(int count READ count NOTIFY sigCountChanged)

public:
    explicit MyCppModel(QObject *parent = nullptr);

    enum {
        Role1 = Qt::UserRole
        Role2,
        Role3
    };

    // Basic functionality:
    int rowCount(const QModelIndex &amp;parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &amp;index, int role = Qt::DisplayRole) const override;

    virtual QHash&lt;int, QByteArray&gt; roleNames() const override;

    CppContainer *getContainer() const;
    void setContainer(CppContainer *container);

    Q_INVOKABLE QVariantMap get(int row);    
    int count() const;
signals:
    void sigContainerChanged();
    void sigCountChanged();
public slots:
    Q_INVOKABLE void refreshIndex(UInt32);
private:

    CppContainer *m_container;
};
</code></pre>
]]></description><link>https://forum.qt.io/post/605686</link><guid isPermaLink="true">https://forum.qt.io/post/605686</guid><dc:creator><![CDATA[romain.donze]]></dc:creator><pubDate>Thu, 09 Jul 2020 06:01:21 GMT</pubDate></item><item><title><![CDATA[Reply to &quot;Rotate&quot; TableView on Wed, 08 Jul 2020 21:10:12 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Are you using a C++ model ? If so you can use a proxy that does that.</p>
]]></description><link>https://forum.qt.io/post/605641</link><guid isPermaLink="true">https://forum.qt.io/post/605641</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 08 Jul 2020 21:10:12 GMT</pubDate></item></channel></rss>