Mousemove event



  • 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());
    }
    }@



  • 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 ?



  • yes i have enbaled mouse tracking
    but it need a click to active
    i don't know why?



  • 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?



  • I merged in the above post that was posted as a separate topic. I think it belongs to this one.



  • 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.



  • 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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.