Pregunta

How can I define onmouseover and click event for a QLineEdit? I want to make 2 signals as onmouseover() and clicked() for QLineEdit

¿Fue útil?

Solución 2

I'm afraid, you'll have to inherit QLineEdit and override void mouseMoveEvent ( QMouseEvent * event ) and void mousePressEvent ( QMouseEvent * event ) (or void mouseReleaseEvent ( QMouseEvent * event ) if you wish). And don't forget to call setMouseTracking(true); to track mouse moves, when no mouse button is held.

Otros consejos

You can install an event filter on your QLineEdit.

Here's an example:

QLineEdit *line_edit = new QLineEdit(this);
ui->verticalLayout->addWidget(line_edit);
line_edit->installEventFilter(this);

And in your event filter function you can do something like this: (This is a function you override)

bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
    if(event->type() == QEvent::MouseButtonPress)
    {
        qDebug() << "CLICK";
    }
    if(event->type() == QEvent::MouseMove)
    {
        qDebug() << "MOUSE OVER";
    }
    return false;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top