<?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 set different background colors for rows in qtreeview]]></title><description><![CDATA[<p dir="auto">Tried to do it as follows:<br />
model()-&gt;setData(  index, QVariant( QColor ), Qt::BackgroundRole );<br />
No success. Any recommendation?</p>
]]></description><link>https://forum.qt.io/topic/127050/how-to-set-different-background-colors-for-rows-in-qtreeview</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 10:32:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/127050.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 May 2021 13:36:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to how to set different background colors for rows in qtreeview on Thu, 27 May 2021 17:57:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a> Excellent! Thanks.</p>
]]></description><link>https://forum.qt.io/post/661923</link><guid isPermaLink="true">https://forum.qt.io/post/661923</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Thu, 27 May 2021 17:57:06 GMT</pubDate></item><item><title><![CDATA[Reply to how to set different background colors for rows in qtreeview on Thu, 27 May 2021 17:45:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/joecfd">@<bdi>JoeCFD</bdi></a> said in <a href="/post/661904">how to set different background colors for rows in qtreeview</a>:</p>
<blockquote>
<p dir="auto">QFileSystemModel</p>
</blockquote>
<p dir="auto">This model only handles <code>Qt::EditRole</code>.</p>
<p dir="auto">You can use <code>RoleMaskProxyModel</code> from <a href="https://github.com/VSRonin/QtModelUtilities" target="_blank" rel="noopener noreferrer nofollow ugc">this library</a> to support other roles. See <a href="https://github.com/VSRonin/QtModelUtilities/blob/master/examples/exam_RoleMaskProxyModel/exam_rolemaskhighlight.cpp" target="_blank" rel="noopener noreferrer nofollow ugc">this example</a></p>
]]></description><link>https://forum.qt.io/post/661918</link><guid isPermaLink="true">https://forum.qt.io/post/661918</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Thu, 27 May 2021 17:45:06 GMT</pubDate></item><item><title><![CDATA[Reply to how to set different background colors for rows in qtreeview on Thu, 27 May 2021 16:58:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> That is how it works. If qtreewidget is used, it has setData. But qtreeview does not have setData and its properties are manipulated with model.</p>
]]></description><link>https://forum.qt.io/post/661910</link><guid isPermaLink="true">https://forum.qt.io/post/661910</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Thu, 27 May 2021 16:58:57 GMT</pubDate></item><item><title><![CDATA[Reply to how to set different background colors for rows in qtreeview on Thu, 27 May 2021 16:54:59 GMT]]></title><description><![CDATA[<p dir="auto">I use alternating color feature which solves my problem while I need only two colors. But that setData does not work is weird.</p>
]]></description><link>https://forum.qt.io/post/661908</link><guid isPermaLink="true">https://forum.qt.io/post/661908</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Thu, 27 May 2021 16:54:59 GMT</pubDate></item><item><title><![CDATA[Reply to how to set different background colors for rows in qtreeview on Thu, 27 May 2021 16:30:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/joecfd">@<bdi>JoeCFD</bdi></a> said in <a href="/post/661904">how to set different background colors for rows in qtreeview</a>:</p>
<blockquote>
<p dir="auto">QFileSystemModel of qt 5.15.2</p>
</blockquote>
<p dir="auto">So why should this model handle setData() with Qt::BackgroundRole? btw: setData() has a return value...</p>
]]></description><link>https://forum.qt.io/post/661905</link><guid isPermaLink="true">https://forum.qt.io/post/661905</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Thu, 27 May 2021 16:30:43 GMT</pubDate></item><item><title><![CDATA[Reply to how to set different background colors for rows in qtreeview on Thu, 27 May 2021 16:20:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> QFileSystemModel of qt 5.15.2</p>
]]></description><link>https://forum.qt.io/post/661904</link><guid isPermaLink="true">https://forum.qt.io/post/661904</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Thu, 27 May 2021 16:20:06 GMT</pubDate></item><item><title><![CDATA[Reply to how to set different background colors for rows in qtreeview on Thu, 27 May 2021 15:20:14 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
But what model type is it?<br />
If a custom model it will be handled by the data function when asked for the BackgroundRole.</p>
]]></description><link>https://forum.qt.io/post/661896</link><guid isPermaLink="true">https://forum.qt.io/post/661896</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Thu, 27 May 2021 15:20:14 GMT</pubDate></item><item><title><![CDATA[Reply to how to set different background colors for rows in qtreeview on Thu, 27 May 2021 14:59:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/n-2204">@<bdi>n-2204</bdi></a> said in <a href="/post/661883">how to set different background colors for rows in qtreeview</a>:</p>
<blockquote>
<p dir="auto">QBrush(QColor(240, 248, 255))</p>
</blockquote>
<p dir="auto">Thanks. I have similar code for table widget and it works. But this does not work for qtreeview somehow.</p>
]]></description><link>https://forum.qt.io/post/661889</link><guid isPermaLink="true">https://forum.qt.io/post/661889</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Thu, 27 May 2021 14:59:10 GMT</pubDate></item><item><title><![CDATA[Reply to how to set different background colors for rows in qtreeview on Thu, 27 May 2021 14:20:14 GMT]]></title><description><![CDATA[<p dir="auto">check this is code to set same color in column in Qtableview ..might be helpful</p>
<pre><code>QAbstractItemModel* table1 = ui.tableView_1-&gt;model();
for (int row = 0; row &lt; table1-&gt;rowCount(); ++row) {
    for (int column : {0, 1, 2)
        table1-&gt;setData(table1-&gt;index(row, column), QBrush(QColor(240, 248, 255)), Qt::BackgroundRole);
</code></pre>
]]></description><link>https://forum.qt.io/post/661883</link><guid isPermaLink="true">https://forum.qt.io/post/661883</guid><dc:creator><![CDATA[n-2204]]></dc:creator><pubDate>Thu, 27 May 2021 14:20:14 GMT</pubDate></item><item><title><![CDATA[Reply to how to set different background colors for rows in qtreeview on Thu, 27 May 2021 13:57:51 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://www.qtcentre.org/threads/61716-Set-the-color-of-a-row-in-a-qtreeview" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.qtcentre.org/threads/61716-Set-the-color-of-a-row-in-a-qtreeview</a><br />
found one here. Kind of messy.</p>
]]></description><link>https://forum.qt.io/post/661881</link><guid isPermaLink="true">https://forum.qt.io/post/661881</guid><dc:creator><![CDATA[JoeCFD]]></dc:creator><pubDate>Thu, 27 May 2021 13:57:51 GMT</pubDate></item></channel></rss>