<?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[[solved] Trouble getting color from QTableWidgetItem]]></title><description><![CDATA[<p dir="auto">Hello, I am trying to do things like change the background color of a QTableWidgetItem when I click on it.</p>
<p dir="auto">@    QTableWidgetItem *cell = ui-&gt;tableWidget-&gt;itemAt( index.column(), index.row() );<br />
QColor color = cell-&gt;background().color();  //test code<br />
int r=40; int g=60; int b=80; int a=0;<br />
color.getRgb( &amp;r, &amp;g, &amp;b, &amp;a );  //OR<br />
r=color.red(); g=color.green(); b=color.blue();<br />
qDebug() &lt;&lt; "r=" &lt;&lt; r &lt;&lt; " g=" &lt;&lt; g &lt;&lt; " b=" &lt;&lt; b;@</p>
<p dir="auto">Both getRgb and color.red() etc. are returning 0,0,0.  Some of the cells are gray, some of them are white.  Why am I not getting the correct color?<br />
Thanks<br />
Ron</p>
]]></description><link>https://forum.qt.io/topic/42869/solved-trouble-getting-color-from-qtablewidgetitem</link><generator>RSS for Node</generator><lastBuildDate>Sat, 02 May 2026 04:19:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/42869.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 Jun 2014 17:06:03 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [solved] Trouble getting color from QTableWidgetItem on Mon, 23 Jun 2014 18:22:43 GMT]]></title><description><![CDATA[<p dir="auto">I figured it out.  QTableWidgetItem::itemAt "returns the item at the position equivalent to QPoint(ax, ay) in the table widget's coordinate system" not column and row in the table.  I changed itemAt() to item() and reversed row/column.  Here is what works:</p>
<p dir="auto">@QTableWidgetItem *cell = ui-&gt;tableWidget-&gt;item( index.row(), index.column() );<br />
QColor color = cell-&gt;background().color();<br />
int r=0; int g=0; int b=0; int a=0;<br />
color.getRgb( &amp;r, &amp;g, &amp;b, &amp;a );<br />
qDebug() &lt;&lt; "r=" &lt;&lt; r &lt;&lt; " g=" &lt;&lt; g &lt;&lt; " b=" &lt;&lt; b;<br />
qDebug() &lt;&lt; "checked=" &lt;&lt; cell-&gt;checkState();  //I made some of the cells Qt::ItemIsUserCheckable@</p>
]]></description><link>https://forum.qt.io/post/233099</link><guid isPermaLink="true">https://forum.qt.io/post/233099</guid><dc:creator><![CDATA[BasicPoke]]></dc:creator><pubDate>Mon, 23 Jun 2014 18:22:43 GMT</pubDate></item><item><title><![CDATA[Reply to [solved] Trouble getting color from QTableWidgetItem on Mon, 23 Jun 2014 17:37:31 GMT]]></title><description><![CDATA[<p dir="auto">Apparently I am not getting the cell correctly because cell-&gt;setText("abc") does not work.</p>
]]></description><link>https://forum.qt.io/post/233097</link><guid isPermaLink="true">https://forum.qt.io/post/233097</guid><dc:creator><![CDATA[BasicPoke]]></dc:creator><pubDate>Mon, 23 Jun 2014 17:37:31 GMT</pubDate></item></channel></rss>