<?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[Forbid leaving a QLineEdit]]></title><description><![CDATA[<p dir="auto">Hi to everybody.</p>
<p dir="auto">I know it is bad GUI programming style but I need to forbid leaving a QLineEdit if its content is not "proper".</p>
<p dir="auto">I tried using focusOut event and inside it using setFocus but it seems is not the right thing to do. It seems that calling setFocus from inside focusOut/In events is not supported.<br />
I'm thinking about setting a one-shot-timer to call a method to set the focus...</p>
<p dir="auto">I read about QValidator, but I read contrasting info on this point.</p>
<p dir="auto">Is there a way to know that a widget is about to lose focus and stop the it ?</p>
]]></description><link>https://forum.qt.io/topic/11423/forbid-leaving-a-qlineedit</link><generator>RSS for Node</generator><lastBuildDate>Mon, 18 May 2026 11:57:18 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/11423.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Nov 2011 12:07:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Fri, 18 Nov 2011 19:36:43 GMT]]></title><description><![CDATA[<p dir="auto">As you want to force your users through the line edits, I would go for another approach:</p>
<ul>
<li>disable every line edit but the first</li>
<li>once the first line edit has acceptable input, enable the next line edit</li>
<li>when the content changes to inacceptable input, disable all line edits following the current one</li>
<li>and so on</li>
</ul>
<p dir="auto">This way your users have a clear presentation of which controls are usable at a given moment.</p>
<p dir="auto">I personally would be <em>really</em> embarrassed by an UI that makes me widgets appear as active, which actually are not. This is against all UI design principles. Such an application is plain not acceptable from a UI point of view.</p>
]]></description><link>https://forum.qt.io/post/117420</link><guid isPermaLink="true">https://forum.qt.io/post/117420</guid><dc:creator><![CDATA[goetz]]></dc:creator><pubDate>Fri, 18 Nov 2011 19:36:43 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Fri, 18 Nov 2011 15:47:32 GMT]]></title><description><![CDATA[<p dir="auto">Thank you everybody for your answers.</p>
<p dir="auto">I was finally able to obtain a consistent result, after reading Qt source code and understanding what the different events do.</p>
<p dir="auto">So in the focusOut event I keep track that the object needs to have focus back and in the focusIn of the next widget, the first thing I do is to set focus back and returning true (so that doesn't start the blinking cursor).</p>
<p dir="auto">I have not tried with other widgets, probably there will be no other widgets other than QLineEdit since this is a porting of a text-mode application: forms are defined in a database and so we need to comply with the text-mode forms.</p>
<p dir="auto">Alternatively I already created a couple of tests, doing something similar to what you propose.</p>
<p dir="auto">Thank you</p>
]]></description><link>https://forum.qt.io/post/117397</link><guid isPermaLink="true">https://forum.qt.io/post/117397</guid><dc:creator><![CDATA[fp615]]></dc:creator><pubDate>Fri, 18 Nov 2011 15:47:32 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Fri, 18 Nov 2011 07:01:28 GMT]]></title><description><![CDATA[<p dir="auto">Well, that was my point really. There is no way you are going to keep the user "in" the current widget, if you do not disable the other elements. As Volker sais: not all controls need focus to be usable. In linux, I think you even may be able to middle-click a line edit and paste text without the line edit having focus (I'd have to try that). And yes, it <em>is</em> a last resort, but at least it is clear to the user. IMHO better than restricting the user to a line edit without giving him a hint that that is the case...</p>
<p dir="auto">But, indeed, I would stick to disabling the "Next" or "Save" or whatever your action button is, and just put a hint to the user what is wrong, and what he needs to do to enable it.</p>
]]></description><link>https://forum.qt.io/post/117312</link><guid isPermaLink="true">https://forum.qt.io/post/117312</guid><dc:creator><![CDATA[andre]]></dc:creator><pubDate>Fri, 18 Nov 2011 07:01:28 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 22:05:07 GMT]]></title><description><![CDATA[<p dir="auto">Disabling the rest of the GUI would be an option of last resort in my opinion. Most times you'll have some kind of "save" or "next" button - IMHO it would be sufficient to disable that one.</p>
<p dir="auto">Another point to take into account: you may succeed to disable the focus, but you will not disable the other widgets, so your user can change a spinbox, check/uncheck checkboxes, select from a combobox etc. with the mouse.</p>
]]></description><link>https://forum.qt.io/post/117284</link><guid isPermaLink="true">https://forum.qt.io/post/117284</guid><dc:creator><![CDATA[goetz]]></dc:creator><pubDate>Thu, 17 Nov 2011 22:05:07 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 20:05:13 GMT]]></title><description><![CDATA[<p dir="auto">How about you just disable the rest of your GUI elements as long as the current value is not valid? Sounds like horrible UI to me, but...</p>
]]></description><link>https://forum.qt.io/post/117278</link><guid isPermaLink="true">https://forum.qt.io/post/117278</guid><dc:creator><![CDATA[andre]]></dc:creator><pubDate>Thu, 17 Nov 2011 20:05:13 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 16:11:28 GMT]]></title><description><![CDATA[<p dir="auto">What about focusNextPrevChild ? in QWidget::event, when TAB/BACKTAB is pressed, focusNextPrevChild is called...</p>
<p dir="auto">focusNextPrevChild finds the next/prev widget and calls setFocus on it.</p>
<p dir="auto">setFocus emits focusOut and focusIn and there is no way to avoid this (well, I may override setFocus...)</p>
<p dir="auto">I'm looking in Qt source code where focus is set after mouse click</p>
<p dir="auto">[quote author="cincirin" date="1321538915"]I'm not sure. Maybe your idea, with single shot timer<br />
@<br />
QTimer::singleShot(0, yourLineEdit, SLOT(setFocus()))<br />
@[/quote]</p>
]]></description><link>https://forum.qt.io/post/117258</link><guid isPermaLink="true">https://forum.qt.io/post/117258</guid><dc:creator><![CDATA[fp615]]></dc:creator><pubDate>Thu, 17 Nov 2011 16:11:28 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 14:08:35 GMT]]></title><description><![CDATA[<p dir="auto">I'm not sure. Maybe your idea, with single shot timer<br />
@<br />
QTimer::singleShot(0, yourLineEdit, SLOT(setFocus()))<br />
@</p>
]]></description><link>https://forum.qt.io/post/117244</link><guid isPermaLink="true">https://forum.qt.io/post/117244</guid><dc:creator><![CDATA[cincirin]]></dc:creator><pubDate>Thu, 17 Nov 2011 14:08:35 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 14:03:15 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="cincirin" date="1321538367"][quote author="fp615" date="1321533645"]TAB/BACKTAB the focus is moved away from the QLineEdit ?[/quote]<br />
It happens with or without validators.[/quote]</p>
<p dir="auto">Thanks for the answer, this will save me writing a test program.</p>
<p dir="auto">Do you know about the use of setFocus inside a focusOut/In event ?</p>
]]></description><link>https://forum.qt.io/post/117241</link><guid isPermaLink="true">https://forum.qt.io/post/117241</guid><dc:creator><![CDATA[fp615]]></dc:creator><pubDate>Thu, 17 Nov 2011 14:03:15 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 13:59:27 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="fp615" date="1321533645"]TAB/BACKTAB the focus is moved away from the QLineEdit ?[/quote]<br />
It happens with or without validators.</p>
]]></description><link>https://forum.qt.io/post/117238</link><guid isPermaLink="true">https://forum.qt.io/post/117238</guid><dc:creator><![CDATA[cincirin]]></dc:creator><pubDate>Thu, 17 Nov 2011 13:59:27 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 13:43:12 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="BilbonSacquet" date="1321536803"]yes, you get a QEvent::FocusOut message event ... [/quote]</p>
<p dir="auto">using setFocus in a focusOut/in event creates, in my test programs (that may be wrong) confusing situations:</p>
<ul>
<li>multiple blinking cursors</li>
<li>cursor blinking in one QLineEdit but focus on another...</li>
</ul>
<p dir="auto">and other strangenesses..</p>
<p dir="auto">thanks<br />
Francesco</p>
]]></description><link>https://forum.qt.io/post/117227</link><guid isPermaLink="true">https://forum.qt.io/post/117227</guid><dc:creator><![CDATA[fp615]]></dc:creator><pubDate>Thu, 17 Nov 2011 13:43:12 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 13:40:32 GMT]]></title><description><![CDATA[<p dir="auto">[quote author="Volker" date="1321533645"]What confuses you with the validators?[/quote]</p>
<p dir="auto">About validators I post the question directly:<br />
if I'm editing a QLineEdit and for the current text the validator returns Invalid, if I press TAB/BACKTAB the focus is moved away from the QLineEdit ?</p>
<p dir="auto">Then back to the "general" question: is it possible and if yes how, to setFocus to a QLineEdit during a focusOut/In event ?</p>
<p dir="auto">Example, in a field I can enter the iso country codes, so I can set maximum length and force alpha chars. But I can't allow to move focus to other QLineEdits until the country code is validated !</p>
<p dir="auto">Probably in a brand new program, following GUI guidelines, I would build the form differently, but in this case, I need to do in this way.</p>
<p dir="auto">thanks</p>
]]></description><link>https://forum.qt.io/post/117226</link><guid isPermaLink="true">https://forum.qt.io/post/117226</guid><dc:creator><![CDATA[fp615]]></dc:creator><pubDate>Thu, 17 Nov 2011 13:40:32 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 13:33:23 GMT]]></title><description><![CDATA[<p dir="auto">yes, you get a QEvent::FocusOut message event ...</p>
]]></description><link>https://forum.qt.io/post/117221</link><guid isPermaLink="true">https://forum.qt.io/post/117221</guid><dc:creator><![CDATA[BilbonSacquet]]></dc:creator><pubDate>Thu, 17 Nov 2011 13:33:23 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 13:01:52 GMT]]></title><description><![CDATA[<p dir="auto">... or "Input Mask":<a href="http://doc.qt.nokia.com/stable/qlineedit.html#inputMask-prop" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.nokia.com/stable/qlineedit.html#inputMask-prop</a> is other kind of validation. Neither it does not help you ?</p>
]]></description><link>https://forum.qt.io/post/117219</link><guid isPermaLink="true">https://forum.qt.io/post/117219</guid><dc:creator><![CDATA[cincirin]]></dc:creator><pubDate>Thu, 17 Nov 2011 13:01:52 GMT</pubDate></item><item><title><![CDATA[Reply to Forbid leaving a QLineEdit on Thu, 17 Nov 2011 12:40:45 GMT]]></title><description><![CDATA[<p dir="auto">What confuses you with the validators?</p>
]]></description><link>https://forum.qt.io/post/117212</link><guid isPermaLink="true">https://forum.qt.io/post/117212</guid><dc:creator><![CDATA[goetz]]></dc:creator><pubDate>Thu, 17 Nov 2011 12:40:45 GMT</pubDate></item></channel></rss>