Mousemove event
-
wrote on 21 Oct 2011, 08:07 last edited by
hi to every one
i want to have a qpushbutton that load two icon
whenever mouse goes to its place it load another icon and when it left its place it load the default icon
i use this code but it does'nt work for me , do you know what should i do?
baseaddress is the baseaddress of icons(QString)
and normall and over is the name of icons(QString)
mybutton class declared by subcalssing qpushbutton
@void mybutton::mouseMoveEvent ( QMouseEvent * e)
{
if((e->x() <=0 || e->x()>=this->width()) && (e->y() <=0 || e->y()>=this->height()))
{
QPixmap pp;
pp.load(baseaddress+normall);
this->setIcon(pp);
this->setIconSize(pp.size());
this->setFixedSize(pp.size());
}else
{
QPixmap pp;
pp.load(baseaddress+over);
this->setIcon(pp);
this->setIconSize(pp.size());
this->setFixedSize(pp.size());
}
}@ -
wrote on 21 Oct 2011, 11:33 last edited by
I would suggest you to try "QWidget::leaveEvent":http://doc.qt.nokia.com/latest/qwidget.html#leaveEvent or "QWidget::enterEvent":http://doc.qt.nokia.com/latest/qwidget.html#enterEvent.
Another thing, have you enabled "mouseTracking":http://doc.qt.nokia.com/latest/qwidget.html#mouseTracking-prop ?
-
wrote on 21 Oct 2011, 14:11 last edited by
yes i have enbaled mouse tracking
but it need a click to active
i don't know why? -
wrote on 22 Oct 2011, 05:29 last edited by
hi i have a calss name mybutton that i subclass it from qpushbutton and in my constructor i use
@setmousetracking(true);@
and i reimplement functions:
@enterEvent(QEvent *);
leaveEvent(QEvent *);
mousePressEvent(QMouseEvent *);
mouseReleaseEvent(QMouseEvent *);
@
and it works fine unless i should click one time on my program to work these functions,
should i do anything else? -
wrote on 22 Oct 2011, 10:44 last edited by
I merged in the above post that was posted as a separate topic. I think it belongs to this one.
-
wrote on 22 Oct 2011, 11:36 last edited by
bq. and it works fine unless i should click one time on my program to work these functions,
should i do anything else?I tryed with these reimplemented functions:
@
void MyButton::enterEvent ( QEvent * event )
{
qDebug() << "ENTER EVENT";
}void MyButton::leaveEvent ( QEvent * event )
{
qDebug() << "LEAVE EVENT";
}@even if another application has focus, the MyButton receive leave and enter events. At last on linux it works fine.
-
wrote on 23 Oct 2011, 08:39 last edited by
I've reimplemented mouseMoveEvent and enabled mouseTracking. When none button is pressed my widget receivers mouseMoveEvent only when cursor is leaving the widget. Shouldn't it receive this event all the time when i move mouse and mouse cursor remains on the widget?
5/7