Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Mousemove event
Qt 6.11 is out! See what's new in the release blog

Mousemove event

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 10.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kitten
    wrote on last edited by
    #1

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

    www.kitten.mihanblog.com

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deimos
      wrote on last edited by
      #2

      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 ?

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kitten
        wrote on last edited by
        #3

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

        www.kitten.mihanblog.com

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kitten
          wrote on last edited by
          #4

          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?

          www.kitten.mihanblog.com

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • D Offline
              D Offline
              deimos
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                p-himik
                wrote on last edited by
                #7

                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?

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved