<?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] QStyleOptionViewItem draw text ?]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I am working on a tableView that uses a QStyledItemDelegate. Inside the itemDelegate I am trying to render a QLineEdit with someText but somehow the text is not displayed. eg</p>
<p dir="auto">@if (condition)<br />
{<br />
QStyleOptionViewItem item(option);<br />
item.rect = option.rect;<br />
item.text =  "Hello World";<br />
item.palette = QPalette(Qt::Red); // just for test</p>
<p dir="auto">QApplication::style()-&gt;drawPrimitive(QStyle::PE_PanelLineEdit, &amp;item, painter);<br />
QApplication::style()-&gt;drawPrimitive(QStyle::PE_FrameLineEdit, &amp;item, painter);<br />
}@</p>
<p dir="auto">But the text is not rendered at all but if I use qDebug() &lt;&lt; item.text;  it gives the right output.</p>
<p dir="auto">How to render the text using QStyleOptionViewItem ?</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.qt.io/topic/28415/solved-qstyleoptionviewitem-draw-text</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 06:06:33 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/28415.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Jun 2013 10:09:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Thu, 20 Jun 2013 12:22:47 GMT]]></title><description><![CDATA[<p dir="auto">Thanks Andre,</p>
<p dir="auto">I think then I have to check/set the color for the painter based on properties specified for the lineEdit.</p>
]]></description><link>https://forum.qt.io/post/183582</link><guid isPermaLink="true">https://forum.qt.io/post/183582</guid><dc:creator><![CDATA[Sam]]></dc:creator><pubDate>Thu, 20 Jun 2013 12:22:47 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Thu, 20 Jun 2013 12:10:57 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="Sam" date="1371730152"]and if we are setting the background-color through stylesheets then also its not possible to retrieve the value ?[/quote]<br />
AFAIK: indeed not. The style sheets are not exposed through the public API other then setting them on a widget or the application.</p>
<p dir="auto">I'd love to be proven wrong on this one though!</p>
]]></description><link>https://forum.qt.io/post/183581</link><guid isPermaLink="true">https://forum.qt.io/post/183581</guid><dc:creator><![CDATA[andre]]></dc:creator><pubDate>Thu, 20 Jun 2013 12:10:57 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Thu, 20 Jun 2013 12:09:12 GMT]]></title><description><![CDATA[<p dir="auto">and if we are setting the background-color through stylesheets then also its not possible to retrieve the value ?</p>
<p dir="auto">PS : QPalette::Background return gray color</p>
]]></description><link>https://forum.qt.io/post/183580</link><guid isPermaLink="true">https://forum.qt.io/post/183580</guid><dc:creator><![CDATA[Sam]]></dc:creator><pubDate>Thu, 20 Jun 2013 12:09:12 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Thu, 20 Jun 2013 12:06:07 GMT]]></title><description><![CDATA[<p dir="auto">try QPalette::Background</p>
]]></description><link>https://forum.qt.io/post/183578</link><guid isPermaLink="true">https://forum.qt.io/post/183578</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Thu, 20 Jun 2013 12:06:07 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Thu, 20 Jun 2013 12:03:48 GMT]]></title><description><![CDATA[<p dir="auto">No. It might not even <em>be</em> a color. It might be a brush. Or an image, or...</p>
]]></description><link>https://forum.qt.io/post/183579</link><guid isPermaLink="true">https://forum.qt.io/post/183579</guid><dc:creator><![CDATA[andre]]></dc:creator><pubDate>Thu, 20 Jun 2013 12:03:48 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Thu, 20 Jun 2013 12:01:59 GMT]]></title><description><![CDATA[<p dir="auto">One more question I would like to ask , is there anyway we can get the background-color of the lineEdit which is set through stylesheets like in the above image the yellow color is set through stylesheet.</p>
<p dir="auto">Anything like<br />
lineEdit-&gt;palette().color(QPalette::?????);</p>
]]></description><link>https://forum.qt.io/post/183577</link><guid isPermaLink="true">https://forum.qt.io/post/183577</guid><dc:creator><![CDATA[Sam]]></dc:creator><pubDate>Thu, 20 Jun 2013 12:01:59 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Tue, 18 Jun 2013 11:50:53 GMT]]></title><description><![CDATA[<p dir="auto">thats why i asked ;)</p>
]]></description><link>https://forum.qt.io/post/183258</link><guid isPermaLink="true">https://forum.qt.io/post/183258</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 18 Jun 2013 11:50:53 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Tue, 18 Jun 2013 11:46:28 GMT]]></title><description><![CDATA[<p dir="auto">yes the background color for the lineEdit changes through styleSheets.<br />
Yes easiest way is to change the background color of the cell.</p>
<p dir="auto">Thanks :)</p>
<p dir="auto">PS : I was thinking too complex :)</p>
]]></description><link>https://forum.qt.io/post/183255</link><guid isPermaLink="true">https://forum.qt.io/post/183255</guid><dc:creator><![CDATA[Sam]]></dc:creator><pubDate>Tue, 18 Jun 2013 11:46:28 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Tue, 18 Jun 2013 11:37:52 GMT]]></title><description><![CDATA[<p dir="auto">just draw the text with a simple background is enough for you?</p>
<p dir="auto">How do you exactly change the background color of the line edit when the QValidator fails? By Stylesheet?</p>
]]></description><link>https://forum.qt.io/post/183253</link><guid isPermaLink="true">https://forum.qt.io/post/183253</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 18 Jun 2013 11:37:52 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Tue, 18 Jun 2013 11:34:08 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="raven-worx" date="1371554769"]ok, but why do you want to draw a line edit instead of using a real qlinedit widget?<br />
pro: works our of the box like a qlineedit should<br />
con: may cause performance<br />
[/quote]</p>
<p dir="auto">I can't use setInexWidget()  performance drops heavily !!!</p>
<p dir="auto">bq. Or why do you want to use a QLineEdit widget at all?</p>
<p dir="auto">The lineEdit is initialized in the createEditor(). what else you recommend ?</p>
]]></description><link>https://forum.qt.io/post/183251</link><guid isPermaLink="true">https://forum.qt.io/post/183251</guid><dc:creator><![CDATA[Sam]]></dc:creator><pubDate>Tue, 18 Jun 2013 11:34:08 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Tue, 18 Jun 2013 11:26:09 GMT]]></title><description><![CDATA[<p dir="auto">ok, but why do you want to draw a line edit instead of using a real qlinedit widget?<br />
pro: works our of the box like a qlineedit should<br />
con: may cause performance</p>
<p dir="auto">Or why do you want to draw a QLineEdit widget at all and not just simply the text with a background color?</p>
]]></description><link>https://forum.qt.io/post/183250</link><guid isPermaLink="true">https://forum.qt.io/post/183250</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 18 Jun 2013 11:26:09 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Tue, 18 Jun 2013 11:22:32 GMT]]></title><description><![CDATA[<p dir="auto">Ok i'll explain in detail,</p>
<p dir="auto">The background color(yellow/red) of the lineEdit changes based on the validator and the current text. The tableview cell should render the same palette/effect of the lineEdit.</p>
<p dir="auto">The lineEdit is initialized/editable when a particular cell is clicked. I need to set the same effect for a particular cell. For the tableView each cell contains an object of a class that stores the property like text/palette etc.</p>
<p dir="auto">Eg I need to render something like</p>
<p dir="auto">!<a href="http://img42.imageshack.us/img42/3738/v3c4.png(lineEdit)" target="_blank" rel="noopener noreferrer nofollow ugc">http://img42.imageshack.us/img42/3738/v3c4.png(lineEdit)</a>!</p>
]]></description><link>https://forum.qt.io/post/183246</link><guid isPermaLink="true">https://forum.qt.io/post/183246</guid><dc:creator><![CDATA[Sam]]></dc:creator><pubDate>Tue, 18 Jun 2013 11:22:32 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Tue, 18 Jun 2013 11:05:46 GMT]]></title><description><![CDATA[<p dir="auto">what exactly do you mean?</p>
]]></description><link>https://forum.qt.io/post/183245</link><guid isPermaLink="true">https://forum.qt.io/post/183245</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 18 Jun 2013 11:05:46 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Tue, 18 Jun 2013 10:59:48 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for  a quick reply !!!!</p>
<p dir="auto">I changed style option to QStyleOpionFrameV2 (I just checked the source of qlineedit.cpp )</p>
<p dir="auto">@QApplication::style()-&gt;drawPrimitive(QStyle::PE_PanelLineEdit, &amp;item, painter);</p>
<p dir="auto">QApplication::style()-&gt;drawPrimitive(QStyle::PE_FrameLineEdit, &amp;item, painter);</p>
<p dir="auto">painter-&gt;drawText(QApplication::style()-&gt;subElementRect(QStyle::SE_LineEditContents, &amp;item),text);@</p>
<p dir="auto">Now the text is rendered but there is a little offset on the y() value , anyhow i'll adjust that. But what about the palette how to change that ?</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.qt.io/post/183244</link><guid isPermaLink="true">https://forum.qt.io/post/183244</guid><dc:creator><![CDATA[Sam]]></dc:creator><pubDate>Tue, 18 Jun 2013 10:59:48 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Tue, 18 Jun 2013 10:30:09 GMT]]></title><description><![CDATA[<p dir="auto">I think you're passing the wrong type of style option... Note that you'll also need to render the contents of the line edit, not just the frame.</p>
]]></description><link>https://forum.qt.io/post/183242</link><guid isPermaLink="true">https://forum.qt.io/post/183242</guid><dc:creator><![CDATA[andre]]></dc:creator><pubDate>Tue, 18 Jun 2013 10:30:09 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] QStyleOptionViewItem draw text ? on Tue, 18 Jun 2013 10:29:01 GMT]]></title><description><![CDATA[<p dir="auto">i think the problem is that you just don't draw the text ^^</p>
<p dir="auto">Look at QLineEdit::paintEvent() implementation (&lt;Qt5-src&gt;\qtbase\src\widgets\widgets\qlineedit.cpp).<br />
In there you will see that at the beginning the frame/panel is drawn and then then alot of code follows just for text rendering...</p>
<h1>You can all the code you need from there</h1>
<h1>or just draw the text with QPainter::drawText() into the rect (using <em>QStyle::subElementRect(QStyle::SE_LineEditContents)</em>)</h1>
<h1>maybe the most wasiest way: hold a QLineEdit widget as member in your delegate and render it:</h1>
<p dir="auto">@<br />
m_RenderLineEdit.setGeometry(option.rect);<br />
m_RenderLineEdit.render(painter);<br />
@</p>
]]></description><link>https://forum.qt.io/post/183241</link><guid isPermaLink="true">https://forum.qt.io/post/183241</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 18 Jun 2013 10:29:01 GMT</pubDate></item></channel></rss>