PDA

View Full Version : How to get mouse events(mouse release) on a pushbutton



athulms
7th October 2011, 09:19
How can i get mouse press & mouse release events on a qpush button.
I can get mouse press event of a button by writing its slot. How can i get the mouse release event?? pls help



My purpose is to provide a new cursor image to the cursor when a button is clicked.
I have done it using its slot and restored back the default icon using a timer.


the problem is when i press the mouse button for a long time without release the image will restore on the time out of timer.

I tryed mouse press & mouse release event but it doesnot works for the pushbuttons but works on frames.

pkj
7th October 2011, 09:56
QAbstractButton::pressed() and QAbstractButton::release() signals.


connect(ui->pushButton, SIGNAL(pressed()), this, SLOT(pressed()));
connect(ui->pushButton, SIGNAL(released()), this, SLOT(released()));

have slots ...

void MainWindow::pressed(){
qDebug()<<"hi pressed";
}

void MainWindow::released(){
qDebug()<<"hi released";
}

athulms
7th October 2011, 10:20
k fine.
It works... is mouse events can be used

DmitryNik
8th October 2011, 09:46
Did you try to use an event filter for those purposes?
Link (http://doc.trolltech.com/4.7/qobject.html#installEventFilter)