MHM MHM - 1 month ago 10
Linux Question

how to set onclick signal for all qlineedit to open a widget for keyboard and send data back?

my project in Qt has several widget with multi qlineedit. I want when the user click on each qlineedit the second widget open to show a keyboard with single qlineedit for enter the text and number.

when the user click on ok button, the text on single qlineedit pass to the textbox's which clicked.

How can I do that?

Answer

IMHO, i would do it as following:

1) Create QLineEdit subclass and reimplement focusInEvent - this will handle not only click, but other types of entering the edit also (e.g. via keyboard). In consturctor, you can connect 'openEditor' signal to your custom slot in widget responsible for that (usually the main widget).

2) Promote your edits to custom subclass.

3) From the custom focusInEvent you can, for example emit signal 'openEditor'. There you can use QObject::sender() to determine which edit emitted signal.

4) Implement slot which could do what you need (show new edit with keyboard, set the text in sender (edit emitted editor opening))

Comments