<?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[QLineEdit::setReadOnly(), no signal]]></title><description><![CDATA[<p dir="auto">I have been a bit disappointed to find that <code>QLineEdit::setReadOnly()</code> does not emit a signal.</p>
<p dir="auto">Why do I want one?  All over existing code there are sundry creations of <code>QLineEdit</code>s, and then they may call <code>setReadOnly(False)</code> and  <code>setReadOnly(True)</code> dynamically at later times than construction all over the code.  I decided to aid my poor confused users with a global-stylesheet-file rule:</p>
<pre><code>QLineEdit:read-only {
    background-color: #E5E7E9
}
</code></pre>
<p dir="auto">But as we know, stylesheet rules are not re-evaluated after construction/first being shown till you explicitly <em>force</em> it to update by <em>changing</em> whatever stylesheet it has of its own (nothing to do with the global one), so for that I have defined a helper function:</p>
<pre><code>def widgetPropertyChanged(widget: QWidget):
    # Whenever a widget property is changed
    # (widget.setProperty() or something like QLineEdit.setReadOnly()) called to *alter* a property after initialisation)
    # we have to "alter" widget's stylesheet to cause Qt to refresh for the property change
    ss = widget.styleSheet()
    widget.setStyleSheet("/* */" + (ss if ss is not None else ""))
    widget.setStyleSheet(ss)
</code></pre>
<p dir="auto">Now, at least I could have hooked up existing <code>QLineEdit</code>s with a "change read only" signal to call that.  But with no signal, I either have to track down every occurrence of <code>setReadOnly()</code> and follow it with a call to that helper, or I have to subclass all my <code>QLineEdit</code>s so that I can override <code>setReadOnly()</code> to do it and change all my instances to the derived class.</p>
<p dir="auto">Is that right?  I suppose this would apply equally to any other widget-inbuilt-property which may have a function to alter it and as a result of which i might want to force stylesheet re-evaluation?</p>
]]></description><link>https://forum.qt.io/topic/91481/qlineedit-setreadonly-no-signal</link><generator>RSS for Node</generator><lastBuildDate>Sat, 08 Aug 2026 18:59:09 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/91481.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Jun 2018 15:12:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QLineEdit::setReadOnly(), no signal on Wed, 13 Jun 2018 21:44:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Thank you, but sorry, let me be clear then:</p>
<ul>
<li>From C++ <code>QLineEdit::setReadOnly()</code> is <em>not</em> an overridable, virtual function.</li>
<li>From PyQt, there is a "wrapper" around the whole of <code>QLineEdit</code>, and that has chosen to supply a function, which <em>happens</em> to also be named <code>setReadOnly</code> [but could have been called anything, e.g. <code>pyqtSetReadOnly</code>], which (in Python) <em>is</em> a virtual, overridable function.</li>
<li>PyQt's <code>QLineEdit.setReadOnly()</code> presumably calls the base C++ <code>QLineEdit::setReadOnly()</code> to effect its work.</li>
</ul>
<p dir="auto">The big difference then is:</p>
<ul>
<li>In the case of a <em>genuine</em> <code>virtual</code> Qt C++ function, which I have chosen to override in PyQt, if Qt code <em>internally</em> calls the virtual function from itself it <em>will</em> hit my Python override.</li>
<li>But in the case of this <em>non-</em><code>virtual</code> <code>QLineEdit::setReadOnly()</code>, any internal Qt C++ calls to it will <em>not</em> be affected by the "override" I have defined from Python.</li>
</ul>
<p dir="auto">Does the above sound right?</p>
<p dir="auto"><strong>EDIT</strong> I confirmed with the PyQt creator that this is indeed the way it works.</p>
]]></description><link>https://forum.qt.io/post/463350</link><guid isPermaLink="true">https://forum.qt.io/post/463350</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 13 Jun 2018 21:44:12 GMT</pubDate></item><item><title><![CDATA[Reply to QLineEdit::setReadOnly(), no signal on Wed, 13 Jun 2018 20:04:44 GMT]]></title><description><![CDATA[<p dir="auto">Would it be possible for you to provide a small example that would confirm that ?</p>
]]></description><link>https://forum.qt.io/post/463487</link><guid isPermaLink="true">https://forum.qt.io/post/463487</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Wed, 13 Jun 2018 20:04:44 GMT</pubDate></item><item><title><![CDATA[Reply to QLineEdit::setReadOnly(), no signal on Wed, 13 Jun 2018 21:44:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Thank you, but sorry, let me be clear then:</p>
<ul>
<li>From C++ <code>QLineEdit::setReadOnly()</code> is <em>not</em> an overridable, virtual function.</li>
<li>From PyQt, there is a "wrapper" around the whole of <code>QLineEdit</code>, and that has chosen to supply a function, which <em>happens</em> to also be named <code>setReadOnly</code> [but could have been called anything, e.g. <code>pyqtSetReadOnly</code>], which (in Python) <em>is</em> a virtual, overridable function.</li>
<li>PyQt's <code>QLineEdit.setReadOnly()</code> presumably calls the base C++ <code>QLineEdit::setReadOnly()</code> to effect its work.</li>
</ul>
<p dir="auto">The big difference then is:</p>
<ul>
<li>In the case of a <em>genuine</em> <code>virtual</code> Qt C++ function, which I have chosen to override in PyQt, if Qt code <em>internally</em> calls the virtual function from itself it <em>will</em> hit my Python override.</li>
<li>But in the case of this <em>non-</em><code>virtual</code> <code>QLineEdit::setReadOnly()</code>, any internal Qt C++ calls to it will <em>not</em> be affected by the "override" I have defined from Python.</li>
</ul>
<p dir="auto">Does the above sound right?</p>
<p dir="auto"><strong>EDIT</strong> I confirmed with the PyQt creator that this is indeed the way it works.</p>
]]></description><link>https://forum.qt.io/post/463350</link><guid isPermaLink="true">https://forum.qt.io/post/463350</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Wed, 13 Jun 2018 21:44:12 GMT</pubDate></item><item><title><![CDATA[Reply to QLineEdit::setReadOnly(), no signal on Tue, 12 Jun 2018 21:42:22 GMT]]></title><description><![CDATA[<p dir="auto">Because it's not a virtual function and yes, the documentation is correct (you can check the source code)</p>
<p dir="auto">Python is an entirely different beast. You can modify any element of an object the way you want.</p>
]]></description><link>https://forum.qt.io/post/463332</link><guid isPermaLink="true">https://forum.qt.io/post/463332</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 12 Jun 2018 21:42:22 GMT</pubDate></item><item><title><![CDATA[Reply to QLineEdit::setReadOnly(), no signal on Tue, 12 Jun 2018 11:58:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/killersmath">@<bdi>KillerSmath</bdi></a><br />
Thank you, but I'm afraid neither of your comments address my questions:</p>
<ol>
<li>
<p dir="auto">The selector reference you provided is for CSS, which I know about.  My questions is about Qt's QSS, which has "invented" the <code>:read-only</code> pseudo-state.</p>
</li>
<li>
<p dir="auto">I know all about <code>virtual</code> functions.  My question is: is/how come <a href="http://doc.qt.io/qt-5/qlineedit.html#readOnly-prop" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qlineedit.html#readOnly-prop</a> does not show <code>virtual</code> anywhere, yet it <em>is</em> overridable at least from PyQt?</p>
</li>
</ol>
]]></description><link>https://forum.qt.io/post/463242</link><guid isPermaLink="true">https://forum.qt.io/post/463242</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 12 Jun 2018 11:58:20 GMT</pubDate></item><item><title><![CDATA[Reply to QLineEdit::setReadOnly(), no signal on Tue, 12 Jun 2018 11:48:57 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/463232">QLineEdit::setReadOnly(), no signal</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Thanks, I'm changing over to use <code>QWidget::changeEvent</code>.</p>
<p dir="auto">Any comment on either of the questions in my second post above:</p>
<ol>
<li>
<p dir="auto">Is QSS <code>QLineEdit:read-only</code> simply the same as/a shortcut for <code>QLineEdit[readonly="true"]</code>?</p>
</li>
<li>
<p dir="auto">Am I supposed to know from Qt C++ documentation that, e.g. <code>QLineEdit::setReadOnly()</code> is overridable, because I don't see <code>virtual</code>?  My PyCharm shows it as "overridable" for me from PyQt, but I don't see where that correspond to the C++ documentation?</p>
</li>
</ol>
</blockquote>
<ul>
<li>
<ol>
<li>It's possible both of these selection works as similar but they are differente methods of selection -&gt; <strong>Read More:</strong> <a href="https://webplatform.github.io/docs/guides/advanced_selectors_guide/" target="_blank" rel="noopener noreferrer nofollow ugc">https://webplatform.github.io/docs/guides/advanced_selectors_guide/</a></li>
</ol>
</li>
<li>
<ol start="2">
<li>Yes, you can reimplement this function, but it is good to know why some functions are implemented as Virtual -&gt; <strong>Read More</strong>: <a href="https://stackoverflow.com/questions/2391679/why-do-we-need-virtual-functions-in-c" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/2391679/why-do-we-need-virtual-functions-in-c</a></li>
</ol>
</li>
</ul>
]]></description><link>https://forum.qt.io/post/463240</link><guid isPermaLink="true">https://forum.qt.io/post/463240</guid><dc:creator><![CDATA[KillerSmath]]></dc:creator><pubDate>Tue, 12 Jun 2018 11:48:57 GMT</pubDate></item><item><title><![CDATA[Reply to QLineEdit::setReadOnly(), no signal on Tue, 12 Jun 2018 10:45:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
Thanks, I'm changing over to use <code>QWidget::changeEvent</code>.</p>
<p dir="auto">Any comment on either of the questions in my second post above:</p>
<ol>
<li>
<p dir="auto">Is QSS <code>QLineEdit:read-only</code> simply the same as/a shortcut for <code>QLineEdit[readonly="true"]</code>?</p>
</li>
<li>
<p dir="auto">Am I supposed to know from Qt C++ documentation that, e.g. <code>QLineEdit::setReadOnly()</code> is overridable, because I don't see <code>virtual</code>?  My PyCharm shows it as "overridable" for me from PyQt, but I don't see where that correspond to the C++ documentation?</p>
</li>
</ol>
]]></description><link>https://forum.qt.io/post/463232</link><guid isPermaLink="true">https://forum.qt.io/post/463232</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 12 Jun 2018 10:45:51 GMT</pubDate></item><item><title><![CDATA[Reply to QLineEdit::setReadOnly(), no signal on Fri, 08 Jun 2018 20:19:18 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">You can use an event filter and listen for the <code>ReadOnlyChange</code> event on your QLineEdit objects.</p>
<p dir="auto">Hope it helps.</p>
]]></description><link>https://forum.qt.io/post/462778</link><guid isPermaLink="true">https://forum.qt.io/post/462778</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 08 Jun 2018 20:19:18 GMT</pubDate></item><item><title><![CDATA[Reply to QLineEdit::setReadOnly(), no signal on Fri, 08 Jun 2018 15:23:47 GMT]]></title><description><![CDATA[<p dir="auto">And while I am here, here is a second post for a couple of additional brief clarification requests.  Though please answer the main question first!</p>
<ol>
<li>In my stylesheet I could have written either one of:</li>
</ol>
<pre><code>QLineEdit:read-only { ... }
</code></pre>
<p dir="auto">or</p>
<pre><code>QLineEdit[readonly="true"] { ... }
</code></pre>
<p dir="auto">for my rule.  It didn't seem to matter which, they both respond to the result (after update forcing!) of <code>setReadOnly()</code>.  Are they indeed the same, or is there a subtle difference?</p>
<ol start="2">
<li>Above I said a possible solution would be</li>
</ol>
<blockquote>
<p dir="auto">subclass all my <code>QLineEdit</code>s so that I can override <code>setReadOnly()</code></p>
</blockquote>
<p dir="auto">Now, I write in Python/PyQt, not C++, for my sins.  From the (C++) documentation I can reach from page <a href="http://doc.qt.io/qt-5/qlineedit.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qlineedit.html</a>, <strong>Public Functions</strong>, click on link <code>void 	setReadOnly(bool)</code>, I get taken to <a href="http://doc.qt.io/qt-5/qlineedit.html#readOnly-prop" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qlineedit.html#readOnly-prop</a>, which describes a "Property".  I did <em>not</em> see the definition of <code>setReadOnly()</code> saying <code>virtual</code> somewhere.  So can I override it in a derived class?  Is there something special about these "properties".  Anything special Python/PyQt here?</p>
<p dir="auto">Thanks.</p>
]]></description><link>https://forum.qt.io/post/462738</link><guid isPermaLink="true">https://forum.qt.io/post/462738</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Fri, 08 Jun 2018 15:23:47 GMT</pubDate></item></channel></rss>