Results 1 to 5 of 5

Thread: Starting Point of Rectangle in RubberBand implementation

  1. #1
    Join Date
    Jul 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Starting Point of Rectangle in RubberBand implementation

    Hello everyone
    I've tested the following RubberBand code for an image viewer. But RubberBand rectangle starts at a point a little below the mouse cursor icon instead of at the tip point mouse cursor icon. What can be the reason for this and How can I fix this situation ?

    Sincerely
    Cem

    void ImageMarker::mousePressEvent(QMouseEvent *event)
    {
    origin = event->pos();

    if (!rubberBand)
    {
    rubberBand = new QRubberBand(QRubberBand::Rectangle, imageLabel);
    }

    rubberBand->setGeometry(QRect(origin, QSize()));
    rubberBand->show();
    }

    void ImageMarker::mouseMoveEvent(QMouseEvent *event)
    {
    rubberBand->setGeometry(QRect(origin, event->pos()));
    }

    void ImageMarker::mouseReleaseEvent(QMouseEvent *event)
    {
    rubberBand->hide();
    }

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Starting Point of Rectangle in RubberBand implementation

    Hello,

    You can use
    Qt Code:
    1. QCursor::pos()
    To copy to clipboard, switch view to plain text mode 
    to have the exact position pointed by the cursor.

  3. #3
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Starting Point of Rectangle in RubberBand implementation

    You are passing imageLabel as parent of rubberband instead of this(ImageMarker) and hence the coordinates differ. Try setting this as rubberBand's parent.
    Another way is to map event->pos() to the imageLabel if you want rubberBand's parent to be imageLabel.

    Please wrap the code you post with code tags
    Last edited by Gopala Krishna; 10th July 2007 at 14:38.
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  4. #4
    Join Date
    Jul 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Starting Point of Rectangle in RubberBand implementation

    Thanks for your reply, How can I map event->pos() to the imageLabel ?

  5. #5
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Starting Point of Rectangle in RubberBand implementation

    QWidget::mapToin your case imageLabel->mapTo..
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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.