Results 1 to 10 of 10

Thread: Moving QGraphicsItem with mouse

  1. #1
    Join Date
    Feb 2008
    Posts
    15
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Moving QGraphicsItem with mouse

    I've starting experimenting with QGraphicsScene, QGraphicsView, and have a problem I don't understand. I can move a QGraphicsItem with the mouse, but it can be moved outside of the scene (sceneRect?). I noticed this when I zoom out to see the whole scene. Is there a way to keep the item inside the scene?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Moving QGraphicsItem with mouse

    Yes, check the coordinates of the item and prevent them to get outside the scene.

  3. #3
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Moving QGraphicsItem with mouse

    to monitor graphicsItem position change, take a look at QGraphicsItem::itemChange()

  4. #4
    Join Date
    Feb 2008
    Posts
    15
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Moving QGraphicsItem with mouse

    Quote Originally Posted by totem View Post
    to monitor graphicsItem position change, take a look at QGraphicsItem::itemChange()
    Being a beginner, I haven't ever written a custom item, no idea how. Can you direct me to a tutorial for that? As for my beginning experiments, I'm using a QGraphicsItem rather than a custom item. Does your suggestion apply to that, too? This is all new to me, so any tutorials you can suggest would be helpful. Thanks in advance.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving QGraphicsItem with mouse

    Just follow the link you were given.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Feb 2008
    Posts
    15
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Moving QGraphicsItem with mouse

    Quote Originally Posted by wysota View Post
    Just follow the link you were given.
    That's not a tutorial, it's just a code snippet

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving QGraphicsItem with mouse

    So... you expect to have a tutorial about what? Using a single method? How would such a tutorial be different from the documentation of this method showing an example of use?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Feb 2008
    Posts
    15
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Moving QGraphicsItem with mouse

    Quote Originally Posted by wysota View Post
    So... you expect to have a tutorial about what? Using a single method? How would such a tutorial be different from the documentation of this method showing an example of use?
    I requested a tutorial on how to create a custom item. I've never done that, and have no idea how. Sorry if I wasn't clear on that.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving QGraphicsItem with mouse

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Moving QGraphicsItem with mouse

    Try that link! Suspense rises until you hit:

    "To write your own graphics item, you first create a subclass of QGraphicsItem, and then start by implementing its two pure virtual public functions: boundingRect(), which returns an estimate of the area painted by the item, and paint(), which implements the actual painting. For example: "

    Don't take this the wrong way! Good luck with your first custom item!

    Johannes

Similar Threads

  1. Moving of QGraphicsItem
    By Erlendhg in forum Qt Programming
    Replies: 17
    Last Post: 5th November 2013, 15:04
  2. Update scene after moving QGraphicsItem
    By rogerholmes in forum Newbie
    Replies: 1
    Last Post: 19th January 2010, 05:08
  3. Moving a QButton around the form using the mouse
    By squidge in forum Qt Programming
    Replies: 4
    Last Post: 29th September 2009, 20:19
  4. Moving plot marker with the mouse
    By viridis in forum Qwt
    Replies: 2
    Last Post: 23rd September 2008, 20:39
  5. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 06:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.