Results 1 to 3 of 3

Thread: Subclassing QGraphicsRectItem to have a reference rectangle on an image

  1. #1
    Join Date
    Jul 2011
    Location
    Paris
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Subclassing QGraphicsRectItem to have a reference rectangle on an image

    In my application I am displaying an image on the MainWindow and also the same exact image in a smaller widget just below. For this I have a QGraphicsView, QGraphicsScene and a QGraphicsItem to display the image. And there are zooming capabilities as well.

    Now what I am trying to do is on the small image below, which never changes, I created a QGraphicsRectItem so that when I zoom in the big main image, the rectangle item that is displayed only on the small image, to be as a reference of how much I am zoomed and which portion of the original image I am looking at. Also I want to be able to move this rectangle and have it scroll the main image when I move it.

    The problems I am having is making the QGraphicsRectItem on the scene behave as I want it. For this I have a subclass of QGraphicsRectItem and that item is added to the scene so it is displaying the rectangle on top of the small image fine. I managed to get the events when I press, move and release on the small view, but those events are entered no matter where in the small image I press or move, etc. and I need it to only respond when the press and move are in the Rectangle (when my intention is to move the rectangle).

    For this I tried implementing the HoverEnter and HoverLeave events on the Rect Item but they are never reached. Also to resize the rectangle when I zoom in I tried with setRect and it doesn’t do anything, the rectangle stays the same size on the scene. Can anyone please help me I would really appreciate any ideas, or tips on what might be wrong.

    Thanks!

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Subclassing QGraphicsRectItem to have a reference rectangle on an image

    Did you set the GraphicsItemFlags on the reference rectangle so it can be movable, selectable, focusable, etc? Otherwise, if nothing in the scene is allowed to respond to mouse events, your item won't see them.

  3. #3
    Join Date
    Jul 2011
    Location
    Paris
    Posts
    31
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Subclassing QGraphicsRectItem to have a reference rectangle on an image

    Yes I did! I set my flags like this:

    Qt Code:
    1. setFlags(QGraphicsRectItem::ItemIsMovable | QGraphicsRectItem::ItemIsSelectable |
    2. QGraphicsRectItem::ItemIsFocusable);
    3.  
    4. setAcceptHoverEvents(true);
    To copy to clipboard, switch view to plain text mode 

    After doing this I am having problems..

Similar Threads

  1. Drawing a rectangle over Qlabel image
    By cheyanne in forum Newbie
    Replies: 16
    Last Post: 13th October 2011, 10:05
  2. How to remove focus rectangle on image links in QtWebkit?
    By sfcheng77 in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2011, 07:52
  3. HOW TO DISPLAY A RECTANGLE ON AN IMAGE on a label
    By qt_user in forum Qt Programming
    Replies: 4
    Last Post: 6th August 2010, 16:19
  4. Replies: 1
    Last Post: 24th May 2010, 12:57
  5. Display rectangle on Image
    By parmar ranjit in forum Qt Programming
    Replies: 3
    Last Post: 22nd February 2008, 14:09

Tags for this Thread

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.