PDA

View Full Version : how to catch qMouseEvent



pakine
5th July 2010, 17:17
Hi, i'm a newbie in QT, and i'm working in a proyect with it. now i need to get a simple MouseEvent but i don't get it.
There is a class called ListaMensajes where QScrollArea is placed. Inside i can load PanelTx objects.
The idea is to select the PanelTx object by clicking over each one.



protected:
void clickPanelTxEvent(QMouseEvent *e);

private:
Ui::PanelTxClass ui;


and the definition ..



PanelTx::PanelTx (CArincMsgData *msg, ListaMensajes &listaMensajes, QWidget *parent)
: QWidget(parent), m_cListaMensajes (listaMensajes), m_pMessage (msg)
{
ui.setupUi(this);

m_pDialogPropiedades = 0;

loadValues ();

colorPanelTx(m_pMessage->isEnabledTx ()); //poner color activo-desactivo
}

PanelTx::~PanelTx()
{

}
.............

void PanelTx::clickPanelTxEvent(QMouseEvent *e)
{

if (e->button() == Qt::LeftButton)
{

//this line is just to check it works
this->setPalette(QPalette(Qt::white));

}
else if (e->button() == Qt::RightButton)
{
......
}
}


the line:
this->setPalette(QPalette(Qt::white));
works perfectly with this widget cause im using it in other parts, but i can't get the handler work for the QMouseEvents

could anybody help me?
thanks

tbscope
5th July 2010, 17:49
Are you familiar with c++ and object oriented programming?

You should re-implement the mouse events.

Example:

void MyClass::mousePressEvent ( QMouseEvent * event )
{
//Do something with the event, accept it, and/or pass it to qwidget
}

pakine
7th July 2010, 11:44
thanks for the inconveniences, i have solved it with a eventFilter. I just wanted to manage the click over some panels, and finally i got it.
i have begun 2 weeks ago with c++ and this project, but is still going on.
thanks anyway

riarioriu3
27th June 2012, 10:34
how mousePressEvent () will get called ????
shall i have to call it manually ??

sonulohani
27th June 2012, 10:47
Nope....

include QMouseEvent header file.

Then, override virtual function i.e.;
void mousePressEvent(QMouseEvent *);

Then after that, define it in your cpp file. you dont have to call the function as it will call automatically.
Use documentation.