Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Simple QQuickItem mouseMoveEvent not working
Qt 6.12 LTS is out! See what's new in the release blog

Simple QQuickItem mouseMoveEvent not working

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 456 Views
  • 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.
  • Y Offline
    Y Offline
    Yujeonja
    wrote on last edited by
    #1

    I'm working with QQuickItem and trying to re-implement mouse events. What I want to do is get events when mouse click and move which is mouseMoveEvent exactly do.
    I override mousePressEvent and mouseMoveEvent but only working is mouse pressed.

    Below is the minimal code.

    moveitem.h

    #ifndef MOVEITEM_H
    #define MOVEITEM_H
    
    #include <QQuickItem>
    
    class MoveItem : public QQuickItem
    {
        Q_OBJECT
    public:
        MoveItem(QQuickItem *paremt = nullptr);
    
    protected:
        virtual void mouseMoveEvent(QMouseEvent *event);
        virtual void mousePressEvent(QMouseEvent *event);
    
    signals:
    
    };
    
    #endif // MOVEITEM_H
    

    moveitem.cpp

    #include "moveitem.h"
    
    MoveItem::MoveItem(QQuickItem *parent)
        : QQuickItem(parent)
    {
        setFlag(QQuickItem::ItemHasContents);
        setAcceptedMouseButtons(Qt::LeftButton);
    }
    
    void MoveItem::mouseMoveEvent(QMouseEvent *event)
    {
        qDebug() << event;
        return QQuickItem::mouseMoveEvent(event);
    }
    
    void MoveItem::mousePressEvent(QMouseEvent *event)
    {
        qDebug() << event;
        return QQuickItem::mousePressEvent(event);
    }
    

    main.qml

    import QtQuick 2.12
    import QtQuick.Window 2.12
    
    import Hello 1.0
    
    Window {
      width: 640
      height: 480
      visible: true
      title: qsTr("Hello World")
    
      MoveItem {
        width: 100
        height: 100
      }
    }
    
    

    When build this and run, mouse press in the MoveItem prints mouse event. But press and move mouse, prints nothing.
    What is wrong with my codes?

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