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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:15:32+00:00 2026-06-18T03:15:32+00:00

I’m writing a Qt app that is based around a QGraphicsScene canvas with movable

  • 0

I’m writing a Qt app that is based around a QGraphicsScene canvas with movable shapes on it, and I’m trying to integrate undo-redo functionality. For most functions like creation and deletion of shapes it’s fairly trivial to implement on the QGraphicsScene itself, but I want elements to be movable and for the movement to be undoable. Right now I’m using the rubber band dragmode on the scene and the ItemIsSelectable and ItemIsMovable flags on the items. The problem is that there seems to be no good place to create the QUndoCommand to represent shape movement. If I do it within the QGraphicsScene::itemChange method, then selecting and moving two or more shapes results in separate undo commands for different objects being interleaved and thus are not able to be merged, so undoing results in unexpected behaviour. There’s no event in the QGraphicsScene that gets called when its items are moved around that I can see, so I’m kind of stuck.

The worst case scenario that I see is that I disable the ItemIsMovable flag on my custom QGraphicsItem objects and handle movement entirely in the QGraphicsScene mouse events, but reimplementing that functionality properly seems quite complicated (I checked how Qt does it internally and there is quite a lot of code for handling complicated cases, such as where an object and some of its children are both selected). This seems like the most obvious of use cases for the undo stack (so much so that the example program for the undo framework is a QGraphicsScene program much like mine, except without multiple object movement support) so it seems weird that there’s no built-in way to do it without reimplementing a significant part of the core functionality. Does anyone have any insights or examples of programs that do this?

  • 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-18T03:15:33+00:00Added an answer on June 18, 2026 at 3:15 am

    I solved this somewhat hackishly I think. I added a preMovePoint property to my custom shapes and in the mousePressedEvent of the QGraphicsScene, I set the preMovePoint of each of the selected shapes to their respective current positions, and in mouseReleaseEvent, created a composite move command from the preMovePoint to the current pos of each shape. I would still be interested in knowing if there’s a better way.

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

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am writing an app with both english and french support. The app requests
I'm trying to create an if statement in PHP that prevents a single post
I am writing an app for my school newspaper, which is run completely online
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I am trying to understand how to use SyndicationItem to display feed which is

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.