[Interest] How to display custom data entry form on QLineEdit click ?

Prashanth Udupa prashanth.udupa at gmail.com
Mon Feb 1 17:28:07 CET 2016


Create a Event2Signal class as follows.

#include <QMap>
#include <QList>
#include <QEvent>
#include <QObject>

class Event2Signal : public QObject
{
    Q_OBJECT

public:
    Event2Signal(QObject *parent=0) : QObject(parent) { }
    ~Event2Signal() { }

    void filterEvent(QObject *o, QEvent::Type type) {
        if(!o) return;
        if( m_objectEventsMap.contains(o) ) {
            QList<QEvent::Type> &events = m_objectEventsMap[o];
            if(events.contains(type))
                return;
            events.append(type);
        } else {
            m_objectEventsMap[o].append(type);
            o->installEventFilter(this);
        }
    }

signals:
    void filteredEvent(QObject *o, QEvent *e, bool *filtered);

protected:
    bool eventFilter(QObject *obj, QEvent *e) {
        bool filtered = false;
        emit filteredEvent(obj, e, &filtered);
        return filtered;
    }

private:
    QMap<QObject *, QList<QEvent::Type> > m_objectEventsMap;
};

Now, lets say you want to take some action when user mouse-presses on a
lineEdit. You can do this

Event2Signal *e2s = new Event2Signal(lineEdit);
e2s->filterEvent(lineEdit, QEvent::MouseButtonPress);
connect(e2s, &Event2Signal::filteredEvent, [=]() {
// Activate your form and do other things here..
});

You can reuse this method for handling other kinds of events in signal-slot
style.

Hope this helps.

/ Prashanth

On Mon, 1 Feb 2016 at 21:41 Edward Sutton <edward.sutton at subsite.com> wrote:

> I want to display a form with a numeric touch key pad plus a decimal point
> when user clicks on a QLIneEdit field.
>
> I did not see any signal such as editingStarted.
>
> What are approaches to implementing a custom data entry?
>
> I am targeting Android and iOS with a QWidget app.
>
> -Ed
>

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160201/751ed044/attachment.html>


More information about the Interest mailing list