[Interest] Making a "popup" QLineEdit

Konrad Rosenbaum konrad at silmor.de
Fri Oct 18 15:05:43 CEST 2013


Hi,

On Friday 18 October 2013 14:05:07 Etienne Sandré-Chardonnal wrote:
> I want to do the following GUI element : a QLineEdit which popups when some
> control is clicked, allowing the user for text input, and which hides when
> enter is pressed, or when the user clicks outside the QLineEdit.

I'm not sure this is a good idea. It may look extremely odd.

> How can this be implemented? In other words, I'm looking for an undecorated
> floating widget (modal?) and getting an event when the user clicked
> outside.

First: in the slot handling the button click - calculate the position of the 
QLineEdit. This may be a fixed postion, something relative to the button or 
the exact same geometry of another widget that you want to overlay (this is 
what table and list widgets do when you enter edit mode on a cell).

Handle the size change event for that window and/or the overlayed widget. You 
have to redo the calculation whenever the containing widget/window changes.

You have to derive from QLE to override some behavior.

Create the QLineEdit upon button click and when you know the size (or give a 
hidden QLE the correct geometry and unhide it). Make the QLE the child of its 
top-level window or its main widget on which it pops up and to whose size it 
is limited. It coordinated are relative to its parent!

Chose the parent wisely: the QLE will be limited to its size, move with it, be 
deleted with it, ...

There are two slots that can get called when the user presses Enter or 
otherwise signals he is finished: returnPressed and editingFinished. Clicking 
somewhere else is a Focus Out Event (override the focusOutEvent method).

When you want to do away with it either send it deleteLater to destroy it or 
hide to keep it in the background.


	Konrad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131018/6153edd8/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131018/6153edd8/attachment.sig>


More information about the Interest mailing list