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

  • Home
  • SEARCH
  • 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 6252983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:54:27+00:00 2026-05-24T13:54:27+00:00

I have an application in which the user can draw some points with the

  • 0

I have an application in which the user can draw some points with the mouse and I used QGraphicsView to do that.

I initialized a scene within the QGraphicsView:


    scene = new QGraphicsScene(this);
    scene->setItemIndexMethod(QGraphicsScene::NoIndex);
    scene->setSceneRect(0, 0, 850, 480);
    setScene(scene);
    setCacheMode(CacheBackground);
    setViewportUpdateMode(BoundingRectViewportUpdate);
    setRenderHint(QPainter::Antialiasing);
    setTransformationAnchor(AnchorUnderMouse);
    scale(qreal(1.0), qreal(1.0));
    setMinimumSize(400, 400);

This scene doesn’t cover the entire QGraphicsView and I want the user to be able to draw the points only on the scene. Also the coordinates of the points should be that from the scene not the QGraphicsView area.

This is one screenshot! of how it looks.

I tried doing like this:


    QPoint p = event->pos();
    QRectF sceneRect = this->sceneRect();
    if ((p.x() > sceneRect.left())&&(p.x() < sceneRect.right())&&(p.y() > sceneRect.top())&&
            (p.y() < sceneRect.bottom())){
            QMessageBox msg;
            msg.setText("point is: " + QString::number(p.x()) + ", " + QString::number(p.y()));
            msg.exec();
        }

where I am testing the coordinates. But it doesn’t return the correct results.
How can I constrain the user to draw only on the scene?

  • 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-05-24T13:54:28+00:00Added an answer on May 24, 2026 at 1:54 pm

    Got it. The coordinates of the points created are from the QGraphicsView and not the scene so when putting the constraints on the points to be within the scene it will not work.

    Have to map the points to the scene:

    
        QPointF p = mapToScene(event->pos());
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which has settings where user can define what file will
I have a Java application in which user can give any executable file (.exe)
I have an application which had optional extras depending on if the user has
I have a Java application which I want to shutdown 'nicely' when the user
I have an Excel application in which I want to present the user with
I have a simple iPhone application which uses OpenGL ES (v1) to draw a
I have a console application from which I create a window. I can render
I am developing an application in which user can purchase any image he likes.
Can User follow up on twitter using iphone application. I have done the functionality
I need to make an application in which the user can toggle between two

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.