How to catch MouseBottonPress for QListWidget
QEventFilter doesn't handle QEvent:MouseButtonPress for QListWidget but reacts to QEvent::KeyPress .
Below is a sample code :
Code:
//////////////////////////////HPP File /////////////////////////////////////
class key_press_filter
: public QObject{
Q_OBJECT
protected:
};
{
Q_OBJECT
public:
virtual ~my_list();
};
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////CPP File /////////////////////////////////////
{
addItem("First");
addItem("Second");
addItem("Third");
key_press_filter* kf = new key_press_filter();
installEventFilter(kf);
}
{
my_list* f = static_cast<my_list*>(o);
if (e
->type
() == QEvent::MouseButtonPress||
e
->type
() == QEvent::KeyPress) { f->addItem("aaaaaaaaaaaa");
} else {
// standard event processing
}
}
Plz help me to catch RBM & LBM for QListWidget :confused:
Re: How to catch MouseBottonPress for QListWidget
Try installing the event filter on the view port.
Code:
installEventFilter(kf);
viewport()->installEventFilter(kf);
Re: How to catch MouseBottonPress for QListWidget
Was wrestling with the same problem with QTableWidget this morning! Thanks!
Re: How to catch MouseBottonPress for QListWidget
// OBJECT_NAME means, your instance name of the looking object
// for example:- QTextEdit* sampleEdit = new QTextEdit()
// watched == sampleEdit
if( ( watched == OBJECT_NAME ) && ( e->type()==QEvent::MouseButtonPress ) )
{
QMouseEvent *mousePress = (QMouseEvent*)e;
if ( (mousePress->button() == Qt::LeftButton) || (mousePress->button() == Qt::LeftButton) )
{
// do your code //
return true;
}
}
I think the above code will help you regarding MOUSE PRESS EVENT with QListWidget.