<?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 Add unit with data in columns ?]]></title><description><![CDATA[<p dir="auto">Hi,<br />
1-&gt;How to add unit or text with data in tableview column ?<br />
QAbstractItemModel* table1 = ui.tableView-&gt;model();<br />
table1-&gt;setData(table1-&gt;index(0, 1), speed + QString("rpm"));<br />
as i try this then rpm is coming but speed value come as some special character.<br />
2-&gt; One column is user editable so when user enter any value then unit should add in with numeric value.<br />
3-&gt;as 2 same i need to do for a Qlineedit when user enter value unit should add.<br />
for qlineedit i tried setinputmask()<br />
ui.lineEdit_4-&gt;setInputMask("0000 unit"); // this is only way for lineedit<br />
How to do this?</p>
]]></description><link>https://forum.qt.io/topic/126755/how-to-add-unit-with-data-in-columns</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 16:39:35 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/126755.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 May 2021 12:11:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Wed, 19 May 2021 08:07: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><br />
Setting flags is done on the model, not the view.  Delegates are set on the view, not the model.</p>
<p dir="auto">If you prefer you can have your own separate sub-classes for either/both the models and the views.  In that case you would indeed need separate classes for model flags/item delegates.  (In the case of delegates you can also have separate sub-classes for the view but both using the same delegate class, if desired.)</p>
<p dir="auto">Or, you can share the same model and/or view sub-class for both your tables, instead of having different dedicated ones.  You would put into them some member field of your own to indicates which model/view each instance represents.  Then you can use that in your flags or delegate methods to decide e.g. which columns to edit or hide based on which model/view your instance represents.</p>
]]></description><link>https://forum.qt.io/post/660461</link><guid isPermaLink="true">https://forum.qt.io/post/660461</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 19 May 2021 08:07:10 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Wed, 19 May 2021 04:46:39 GMT]]></title><description><![CDATA[<p dir="auto">I have two Qtableview, in both tables need to make some columns as non editable so for both table I need to create a separate class to set model flags ?</p>
]]></description><link>https://forum.qt.io/post/660423</link><guid isPermaLink="true">https://forum.qt.io/post/660423</guid><dc:creator><![CDATA[n-2204]]></dc:creator><pubDate>Wed, 19 May 2021 04:46:39 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Tue, 18 May 2021 19:41:03 GMT]]></title><description><![CDATA[<p dir="auto">Thanks <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> ok i will read about flags</p>
]]></description><link>https://forum.qt.io/post/660398</link><guid isPermaLink="true">https://forum.qt.io/post/660398</guid><dc:creator><![CDATA[n-2204]]></dc:creator><pubDate>Tue, 18 May 2021 19:41:03 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Tue, 18 May 2021 19:39:30 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/660396">How to Add unit with data in columns ?</a>:</p>
<blockquote>
<blockquote>
<p dir="auto">What does your "noneditabledelegate" do ?</p>
</blockquote>
<p dir="auto">to make columns non editable</p>
</blockquote>
<p dir="auto">As already said, that's not the role of the delegate but the model <a href="https://doc.qt.io/qt-5/qabstractitemmodel.html#flags" target="_blank" rel="noopener noreferrer nofollow ugc">flags</a> method.</p>
]]></description><link>https://forum.qt.io/post/660397</link><guid isPermaLink="true">https://forum.qt.io/post/660397</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 18 May 2021 19:39:30 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Tue, 18 May 2021 19:37:49 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">What does your "noneditabledelegate" do ?</p>
</blockquote>
<p dir="auto">to make columns non editable</p>
]]></description><link>https://forum.qt.io/post/660396</link><guid isPermaLink="true">https://forum.qt.io/post/660396</guid><dc:creator><![CDATA[n-2204]]></dc:creator><pubDate>Tue, 18 May 2021 19:37:49 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Tue, 18 May 2021 19:35:41 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">It's not the role of the delegate to decide what is editable or not, the model flag function is there for that reason.</p>
<p dir="auto">What does your "noneditabledelegate" do ?</p>
<p dir="auto">If you need several different delegates to support suffix, then derive them from the original one providing support for suffix.</p>
]]></description><link>https://forum.qt.io/post/660395</link><guid isPermaLink="true">https://forum.qt.io/post/660395</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 18 May 2021 19:35:41 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Tue, 18 May 2021 19:31:15 GMT]]></title><description><![CDATA[<p dir="auto">Thanks its working!!<br />
But i have dependency<br />
1-&gt;Table1 have 11 column in that i used integerdelegate for 6 column including the "column 8' in this column i need to set suffix also,<br />
2-&gt;and 4 column are non editable using noneditabledelegate, i need to set suffix  for column 9 and make as non editable also.<br />
How can i do this ?</p>
]]></description><link>https://forum.qt.io/post/660392</link><guid isPermaLink="true">https://forum.qt.io/post/660392</guid><dc:creator><![CDATA[n-2204]]></dc:creator><pubDate>Tue, 18 May 2021 19:31:15 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Tue, 18 May 2021 14:55:37 GMT]]></title><description><![CDATA[<p dir="auto">you can make the suffix a property of your delegate:</p>
<pre><code>class SuffixDelegate : public QStyledItemDelegate{
Q_OBJECT
Q_DISABLE_COPY(SuffixDelegate)
public:
explicit SuffixDelegate(QObject* parent = nullptr) : QStyledItemDelegate(parent){}
QString displayText(const QVariant &amp;value, const QLocale &amp;locale) const override{
return QStyledItemDelegate::displayText(value,locale) + m_suffix;
}
void setSuffix(const QString&amp; val) { m_suffix = val; }
const QString&amp; suffix() const {return m_suffix;}
private:
QString m_suffix;
};
</code></pre>
<p dir="auto">Now you can:</p>
<pre><code class="language-cpp">auto rpmDelegate = new SuffixDelegate(this);
rpmDelegate-&gt;setSuffix(QStringLiteral(" rpm"));
auto hpDelegate = new SuffixDelegate(this);
hpDelegate-&gt;setSuffix(QStringLiteral(" hp"));
view-&gt;setItemDelegateForColumn(9,rpmDelegate);
view-&gt;setItemDelegateForColumn(8,hpDelegate );
</code></pre>
]]></description><link>https://forum.qt.io/post/660325</link><guid isPermaLink="true">https://forum.qt.io/post/660325</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Tue, 18 May 2021 14:55:37 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Tue, 18 May 2021 13:38:45 GMT]]></title><description><![CDATA[<p dir="auto">for two column i have different suffix.<br />
for one column -&gt;rpm column 9<br />
and for other-&gt; hp ,column 8<br />
again need to reimplement displayText ?</p>
]]></description><link>https://forum.qt.io/post/660304</link><guid isPermaLink="true">https://forum.qt.io/post/660304</guid><dc:creator><![CDATA[n-2204]]></dc:creator><pubDate>Tue, 18 May 2021 13:38:45 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Tue, 18 May 2021 13:03:43 GMT]]></title><description><![CDATA[<p dir="auto">Just call <code>view-&gt;setItemDelegateForColumn</code> to use the delegate in a specific column only</p>
]]></description><link>https://forum.qt.io/post/660299</link><guid isPermaLink="true">https://forum.qt.io/post/660299</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Tue, 18 May 2021 13:03:43 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Tue, 18 May 2021 13:01:46 GMT]]></title><description><![CDATA[<p dir="auto">Thanks.. <a class="plugin-mentions-user plugin-mentions-a" href="/user/vronin">@<bdi>VRonin</bdi></a>  where i can specify for which column ? displayText?</p>
]]></description><link>https://forum.qt.io/post/660298</link><guid isPermaLink="true">https://forum.qt.io/post/660298</guid><dc:creator><![CDATA[n-2204]]></dc:creator><pubDate>Tue, 18 May 2021 13:01:46 GMT</pubDate></item><item><title><![CDATA[Reply to How to Add unit with data in columns ? on Tue, 18 May 2021 12:50:47 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">How to add unit or text with data in tableview column ?</p>
</blockquote>
<p dir="auto">Subclass <code>QStyledItemDelegate</code> and reimplement <code>displayText</code>. Something like:</p>
<pre><code class="language-cpp">QString displayText(const QVariant &amp;value, const QLocale &amp;locale) const override{
return QStyledItemDelegate::displayText(value,locale) + QStringLiteral(" rpm");
}
</code></pre>
<blockquote>
<p dir="auto">same i need to do for a Qlineedit</p>
</blockquote>
<p dir="auto">Don't use lineedit, use <code>QSpinBox</code>/<code>QDoubleSpinBox</code> (you can call <code>spinBox-&gt;setButtonSymbols(QAbstractSpinBox::NoButtons)</code> if you don't want the buttons). They already have support for <a href="https://doc.qt.io/qt-5/qspinbox.html#prefix-prop" target="_blank" rel="noopener noreferrer nofollow ugc">prefix</a> and <a href="https://doc.qt.io/qt-5/qspinbox.html#suffix-prop" target="_blank" rel="noopener noreferrer nofollow ugc">suffix</a></p>
]]></description><link>https://forum.qt.io/post/660297</link><guid isPermaLink="true">https://forum.qt.io/post/660297</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Tue, 18 May 2021 12:50:47 GMT</pubDate></item></channel></rss>