<?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[Failed to change background color of table widget by QItemDelegate derived class]]></title><description><![CDATA[<pre><code>void MyTableItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &amp;option, const QModelIndex &amp;index) const
{
    QStyleOptionViewItem myOption = option;
    // not work
    myOption.palette.setColor(QPalette::All, QPalette::Background, Qt::red);
    drawBackground(painter, myOption, index);
    // works
    myOption.palette.setColor(QPalette::All, QPalette::Text, Qt::red);
    drawDisplay(painter, myOption, myOption.rect, "Hello");
}
</code></pre>
<p dir="auto">The text color can be changed, but the background color can't be changed.<br />
How to change the background color? (Better in the <strong>paint</strong> function.)<br />
Thanks.</p>
]]></description><link>https://forum.qt.io/topic/80157/failed-to-change-background-color-of-table-widget-by-qitemdelegate-derived-class</link><generator>RSS for Node</generator><lastBuildDate>Thu, 24 Sep 2026 23:15:03 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/80157.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 10 Jun 2017 03:35:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Failed to change background color of table widget by QItemDelegate derived class on Mon, 12 Jun 2017 04:55:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eddy">@<bdi>Eddy</bdi></a> Just don't know why <strong>QItemDelegate::drawBackground</strong> not work</p>
]]></description><link>https://forum.qt.io/post/398864</link><guid isPermaLink="true">https://forum.qt.io/post/398864</guid><dc:creator><![CDATA[jronald]]></dc:creator><pubDate>Mon, 12 Jun 2017 04:55:23 GMT</pubDate></item><item><title><![CDATA[Reply to Failed to change background color of table widget by QItemDelegate derived class on Sun, 11 Jun 2017 15:42:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jronald">@<bdi>jronald</bdi></a><br />
QStyledItemDelegate uses Qt::BackgroundRole</p>
<p dir="auto"><a href="http://doc.qt.io/qt-5/qstyleditemdelegate.html#details" target="_blank" rel="noopener noreferrer nofollow ugc">link to docs</a></p>
]]></description><link>https://forum.qt.io/post/398798</link><guid isPermaLink="true">https://forum.qt.io/post/398798</guid><dc:creator><![CDATA[Eddy]]></dc:creator><pubDate>Sun, 11 Jun 2017 15:42:46 GMT</pubDate></item><item><title><![CDATA[Reply to Failed to change background color of table widget by QItemDelegate derived class on Mon, 12 Jun 2017 04:40:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eddy">@<bdi>Eddy</bdi></a> <strong>QStyledItemDelegate</strong> doesn't have a method of <strong>drawBackground</strong></p>
]]></description><link>https://forum.qt.io/post/398793</link><guid isPermaLink="true">https://forum.qt.io/post/398793</guid><dc:creator><![CDATA[jronald]]></dc:creator><pubDate>Mon, 12 Jun 2017 04:40:23 GMT</pubDate></item><item><title><![CDATA[Reply to Failed to change background color of table widget by QItemDelegate derived class on Sat, 10 Jun 2017 07:39:37 GMT]]></title><description><![CDATA[<p dir="auto">I see in your code you use<br />
QItemDelegate<br />
and<br />
QStyleOptionViewItem</p>
<p dir="auto">AFAIR they don't mix well.</p>
<p dir="auto">Why are you not using QStyledItemDelegate?</p>
]]></description><link>https://forum.qt.io/post/398624</link><guid isPermaLink="true">https://forum.qt.io/post/398624</guid><dc:creator><![CDATA[Eddy]]></dc:creator><pubDate>Sat, 10 Jun 2017 07:39:37 GMT</pubDate></item><item><title><![CDATA[Reply to Failed to change background color of table widget by QItemDelegate derived class on Sat, 10 Jun 2017 07:07:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/eddy">@<bdi>Eddy</bdi></a> Already tried, no error is reported, just not work.</p>
]]></description><link>https://forum.qt.io/post/398620</link><guid isPermaLink="true">https://forum.qt.io/post/398620</guid><dc:creator><![CDATA[jronald]]></dc:creator><pubDate>Sat, 10 Jun 2017 07:07:01 GMT</pubDate></item><item><title><![CDATA[Reply to Failed to change background color of table widget by QItemDelegate derived class on Sat, 10 Jun 2017 06:10:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jronald">@<bdi>jronald</bdi></a></p>
<p dir="auto">instead of QPalette::All which doesn't exist in enum QPalette::ColorGroup<br />
you can choose between :</p>
<pre><code>QPalette::Disabled		 
QPalette::Active		 
QPalette::Inactive		 
QPalette::Normal
</code></pre>
<p dir="auto">what errors did you get?</p>
]]></description><link>https://forum.qt.io/post/398614</link><guid isPermaLink="true">https://forum.qt.io/post/398614</guid><dc:creator><![CDATA[Eddy]]></dc:creator><pubDate>Sat, 10 Jun 2017 06:10:15 GMT</pubDate></item><item><title><![CDATA[Reply to Failed to change background color of table widget by QItemDelegate derived class on Sat, 10 Jun 2017 04:12:52 GMT]]></title><description><![CDATA[<p dir="auto"><strong>QPainter ::fillRect</strong> get it done,  still confused why <strong>QItemDelegate ::drawBackground</strong> not work as expected.</p>
]]></description><link>https://forum.qt.io/post/398611</link><guid isPermaLink="true">https://forum.qt.io/post/398611</guid><dc:creator><![CDATA[jronald]]></dc:creator><pubDate>Sat, 10 Jun 2017 04:12:52 GMT</pubDate></item></channel></rss>