Results 1 to 5 of 5

Thread: Mouse event on a QGraphicsItem that is not in it's own class

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Mouse event on a QGraphicsItem that is not in it's own class

    Quote Originally Posted by xzyerasu View Post
    Let's say I create a QGraphicsItem (rectangle) in a QGraphicsScene (scene), without creating a class for the item:

    Constructur of Mainwindow (.cpp):
    Qt Code:
    1. ui->setupUi(this);
    2. scene = new QGraphicsScene(this);
    3. ui->graphicsView->setScene(scene);
    4. rectangle = scene->addRect(0,0,100,100);
    To copy to clipboard, switch view to plain text mode 

    Is there a way to overwrite a mouse click on the rectangle and make something happen, even if it is not in another class?
    What about showing a tooltip when hovering over it?

    I hope the question is clear and not completely redundant.
    u need to set void QGraphicsItem::setToolTip ( const QString & toolTip ) of the graphicsItem ... if u want to use the hover event hoverEnterEvent ( QGraphicsSceneHoverEvent * ) then u override the graphicsItem instead of using eventFilter ..
    "Behind every great fortune lies a crime" - Balzac

  2. The following user says thank you to wagmare for this useful post:

    xzyerasu (28th December 2012)

  3. #2
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Mouse event on a QGraphicsItem that is not in it's own class

    Thank you, it worked great wit setToolTip. Now however, do you also know if there is a way to use the mouse clicks on this item? (to open a dialog box for example)

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

    Default Re: Mouse event on a QGraphicsItem that is not in it's own class

    If you want, you can handle all events in the scene or in the view.
    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.


Similar Threads

  1. Ogre+qt mouse event (add object with mouse problem)
    By rimie23 in forum Qt Programming
    Replies: 7
    Last Post: 24th April 2012, 10:49
  2. Replies: 3
    Last Post: 7th January 2012, 08:38
  3. QGraphicsItem can't receive mouse leave/enter event
    By wshn13 in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2011, 08:32
  4. Do the layout class can receive the mouse event?
    By tszzp in forum Qt Programming
    Replies: 3
    Last Post: 23rd December 2009, 08:07
  5. can not get mouse double click event for QGraphicsItem
    By learning_qt in forum Qt Programming
    Replies: 2
    Last Post: 14th September 2009, 20:36

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
  •  
Qt is a trademark of The Qt Company.