Results 1 to 11 of 11

Thread: RubberBand Problem

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default RubberBand Problem

    Hi

    I implement QRubberband respectively in the mousePress, mouseMove and mouseRelease methods of QGraphicsScene. But when I do the following I get a runtime error.

    void myScene::mouseMoveEvent(QGraphicsMouseMoveEvent* event)
    {
    myRubberband.setGeometry(QRect(p2, event->screePos()));
    QGraphicsScene::mouseMoveEvent(event);

    }

    The runtime error is : "Do not delete object 'unnamed' during its event handler"

    What's wrong with it?

  2. #2
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: RubberBand Problem

    I solved the problem, but new one arises

    void AhwcsEcdisScene::mousePressEvent(QGraphicsSceneMou seEvent * mouseEvent)
    {
    p2 = mouseEvent->screenPos();


    if(!mRubberband)
    {
    mRubberband = new QRubberBand(QRubberBand::Rectangle);
    pressedFlag = TRUE;
    }


    mRubberband->setGeometry(QRect(p2,QSize()));
    mRubberband->show();
    isReleased = FALSE;
    cout<<"Mouse PRESSED!!"<<endl;
    QGraphicsScene::mousePressEvent(mouseEvent);
    }

    void AhwcsEcdisScene::mouseMoveEvent(QGraphicsSceneMous eEvent * mouseEvent)
    {
    if(pressedFlag && !isReleased)
    mRubberband->setGeometry(QRect(p2,mouseEvent->screenPos()));

    cout<<"Mouse MOVED!!"<<endl;
    QGraphicsScene::mouseMoveEvent(mouseEvent);
    }

    void AhwcsEcdisScene::mouseReleaseEvent(QGraphicsSceneM ouseEvent * mouseEvent)
    {
    if(!mRubberband)
    {
    cout<<"Mouse RELEASED!!"<<endl;
    mRubberband->hide;
    isReleased = TRUE;
    }
    pressedFlag = FALSE;
    QGraphicsScene::mouseReleaseEvent(mouseEvent);
    }

    Mouse is not released! Any ideas?

  3. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: RubberBand Problem

    I done with the problem.

    By the way is there any way to find items(if any) inside the rectangle returned by QRubberBand.rect()?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: RubberBand Problem


  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: RubberBand Problem

    Does this method percepts rubberband or something different?

  6. #6
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: RubberBand Problem

    Hi,

    Can we use QRubberband to select QGraphicsItem from the screen? If yes, then how?


    Regards.

  7. #7
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: RubberBand Problem

    u can find the rect of ur graphic items and check if the qrubberband's rect contains the rect of graphic items..that should work

  8. #8
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: RubberBand Problem

    Hi

    ı already tried it, but there is type mismatching between QRect and QRectF.

  9. #9
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: RubberBand Problem

    well, u can convert a QRect to QRectF or vice versa:

    QRect QRectF::toRect () const
    Returns a QRect based on the values of this rectangle. Note that the coordinates in the returned rectangle are rounded to the nearest integer.

    QRectF QVariant::toRectF () const
    Returns the variant as a QRectF if the variant has type() Rect or RectF; otherwise returns an invalid QRectF.

  10. #10
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: RubberBand Problem

    Ok, I'am trying now. I will report back to you as soos as possible.

    Thanks.

  11. #11
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: RubberBand Problem

    Sorry for the late answer.

    If I do QRubberband::setGeometry(QRect ...), then I couldn't handle the correct rubberband rectangle in order to include QGraphicsItem.

    I used rubberband->rect().

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.