Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to call some function (or slot) when the mouse leaves the space of my QListView (tableView). Normally, you could use the leaveEvent() function. So for example I could write

void MainWindow::leaveEvent(QEvent * event){
    qApp->quit();
}

This works as intended. When the mouse leaves the MainWindow widget, the application quits. However, what if I wanted to quit the application when the mouse leaves my QListView object which is INSIDE of my MainWindow widget?

How do I reimplement a function for this QListView when it was created within QT Creator's form designer?

Here is what I have (unsuccessfully) tried:

void Ui::tableView::leaveEvent(){
    qApp->quit();
}

And below, I have tried using leaveEvent() as a signal, and it says leaveEvent is undefined (can you even use events as SIGNALs?)

connect(ui->tableView, SIGNAL(leaveEvent(QEvent *event)), this, SLOT(testSlot()));

Basically, I am trying to call some function when the mouse leaves my tableView which was created with Qt Creator's form designer. The QListView class seems to have a mouseEntered() SIGNAL, but not mouseLeave() SIGNAL.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Subclass QListView and reimplement the leaveEvent (example):

class MyListView : public QListView
{
     Q_OBJECT

    void MyListView::leaveEvent(QEvent *e){
        QListView::leaveEvent(e);
        anyOtherAction();
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.