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 4118780
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:00:18+00:00 2026-05-20T23:00:18+00:00

I have a problem with a QGrahicsRectItem in a QGraphicsScene . What I would

  • 0

I have a problem with a QGrahicsRectItem in a QGraphicsScene. What I would like is to be able to move the item with mouse. But the problem is that in my case, the dragging rectangle is bigger than the item itself.

Here is the code that I use:

class Test: public QGraphicsView
{
    public:
    Test();

    private:
    virtual void resizeEvent (QResizeEvent * event);
    QGraphicsScene* m_pScene;
};

Test::Test()
{
    m_pScene = new QGraphicsScene();
    setScene(m_pScene);

    m_pScene->setSceneRect(0, 0, 100, 100);

    for (int i = 0 ; i < 10 ; i++)
    {
        QGraphicsRectItem * pItem = new QGraphicsRectItem();
        pItem->setFlag(QGraphicsItem::ItemIsMovable);
        pItem->setBrush(QBrush(QColor(190, 100, 100)));
        pItem->setRect(QRectF(10*i, 10, 5, 80.f));
        pItem->setCursor(Qt::SizeAllCursor);
        m_pScene->addItem(pItem);
    }


    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    resize(600, 200);
    fitInView(scene()->sceneRect());
    show();
}

void Test::resizeEvent(QResizeEvent * event)
{
    QGraphicsView::resizeEvent(event);
    fitInView(scene()->sceneRect());
}

So when I run my program I have this window, and I can drag items. All seems OK.

screen1

But if I look closer the dragging zone is bigger than the item itself. (see the blue rectangle on following screenshot) The blue rectangle means that If I move the mouse in this rectangle, the cursor changes, and I can drag the item.

screen2

I have the feeling that the problem is related to the “fitInView(scene()->sceneRect());” line. If I remove it, then it works.
If I add a ‘scale(5,1)’ for example, there is the same problem.

Do you have an idea of what the problem could be?

  • 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-20T23:00:19+00:00Added an answer on May 20, 2026 at 11:00 pm

    I think you hit this bug: http://bugreports.qt-project.org/browse/QTBUG-17985

    What happens is Qt uses a scene rectangle that is 1×1 in size to test if items are under the cursor. In your (and my) case, 1 unit in the scene is larger than 1 pixel on screen. So the 1×1 rectangle covers more than 1 pixel from the cursor, and touches items that are not under the cursor.

    I have submitted a fix/merge request. You can modify your Qt source to make it work for now.have

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem with jquery submit and post. I would like to submit a
I have problem with Activities navigation, searching works good. Activities hierarchy looks like that:
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with fancybox. I want to write a function that will run
I have problem with php's preg_match.I want to make something like this : When
I have problem with me51n. I have an include in EXIT_SAPLMEREQ_010 that has a
I have problem related with question I've set contentsScale and after that text looking
I have problem with model built like this: class Topping(models.Model): name = models.CharField(max_length=30) class
I have problem with passing variables through views. But, first some code // i
I have a program that draws the contents of a QGraphicsScene to a PNG

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.