Results 1 to 3 of 3

Thread: how to catch the mouse event in the QGrahphicsScene object?

  1. #1
    Join Date
    Jun 2007
    Posts
    10

    Default how to catch the mouse event in the QGrahphicsScene object?

    hi All,
    I have some questions ,need your help!
    the codes as follows:

    QGraphicsScene* scene=new QGraphicsScene(this);
    QGraphicsView* mainview=new QGrahphhicsView(scene);

    QGraphicPixmapItem* piximg=scene->addPixmap(QPixmap(filename));//filename is the opened image filename.
    .......

    the question are:
    1: how to catch the mouse events in the scene? should I reimpliment some methods a class derived from the class QGraphicsScene?
    2:if I want to get a part of the image rectangle field ,how can i do it?

    thank you!

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to catch the mouse event in the QGrahphicsScene object?

    1: how to catch the mouse events in the scene? should I reimpliment some methods a class derived from the class QGraphicsScene?
    See the mouse events from QAbstractScrollArea. You can override those. Just make sure to convert the event mouse position(which is the viewport position) to scene coordinates. This way you get scene coordinates.

    2:if I want to get a part of the image rectangle field ,how can i do it?
    [/CODE]
    One solution is to create a new pixmap with the dimensions of the section and then just take the item's pixmap use a QPainter to write the desired data to destination.
    It is just a matter of translating the painter coordinate system.

    Regards

  3. #3
    Join Date
    Jun 2007
    Posts
    10

    Default Re: how to catch the mouse event in the QGrahphicsScene object?

    thank you ,I will try it...

Similar Threads

  1. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 09:05

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.