Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7975309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:36:45+00:00 2026-06-04T08:36:45+00:00

I have subclassed QGraphicsRectItem , and it’s not receiving any mouse events. I’ve seen

  • 0

I have subclassed QGraphicsRectItem, and it’s not receiving any mouse events. I’ve seen other questions similar to this say I need to enable mouse tracking, but setMouseTracking is in QWidget, and QGraphicsItem does not appear to be a QWidget.

I’ve implemented paint, and that’s working. In my subclassed QGraphicsView I am getting mouse events.

The docs seem to think I should just override the mousePressEvent function (for example) and I should start getting the events. Whether I forward the mousePressEvent to the superclass of my QGraphicsView or not doesn’t seem to make any difference.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T08:36:46+00:00Added an answer on June 4, 2026 at 8:36 am

    In your subclassed QGraphicsView, you need to call the default implementations of overridden mouse event methods if you want them to propagate down to the items. For example:

    CustomView::mousePressEvent(QMouseEvent *event)
    {
        // handle the event as you like
    
        QGraphicsView::mousePressEvent(event); // then call default implementation
    }
    

    If you want to accept hover events, you need to call QGraphicsItem::setAcceptHoverEvents(true);. Otherwise you do not need to enable any particular mouse tracking.

    EDIT: Here is a full working example:

    #include <QtGui>
    
    class CustomView : public QGraphicsView
    {
    protected:
        void mousePressEvent(QMouseEvent *event)
        {
            qDebug() << "Custom view clicked.";
            QGraphicsView::mousePressEvent(event);
        }
    };
    
    class CustomItem : public QGraphicsRectItem
    {
    protected:
        void mousePressEvent(QGraphicsSceneMouseEvent *event)
        {
            qDebug() << "Custom item clicked.";
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        CustomItem item;
        item.setRect(20, 20, 60, 60);
    
        QGraphicsScene scene(0, 0, 100, 100);
        scene.addItem(&item);
    
        CustomView view;
        view.setScene(&scene);
        view.show();
        return a.exec();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a subclass of QGraphicsRectItem. The mouseMoveEvent handler looks like this: void BTNodeGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent*
I have subclassed a UITableViewCell and within this class I want to get it's
I have subclassed Dialog in order to display a popup. This dialog contains a
I have a QGraphicsTextItem subclass that accepts mouse events (i.e. implements wheelEvent() method. How
I have subclassed a UIImageView, and have implemented touchesBegan/Moved/Finished like this: - (void)touchesBegan:(NSSet *)touches
I have subclassed RestDatasource to create my own data source. This is the constructor
I have subclassed UIView so I can draw some lines in it. In this
I have subclassed NSWindow in a NSDocument application in order to receive keyDown events.
I have a ViewController that adds to other subviews which have subclassed uiviewControllers so
This started as a simple problem, but I can't solve it. I have subclassed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.