Results 1 to 8 of 8

Thread: Custom items selection in qgraphicsscene

  1. #1
    Join Date
    Oct 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Custom items selection in qgraphicsscene

    Hello,
    I'm trying to modify default selection behaviour in qgraphicsscene. I'd like to have an event propagation: if a mouse clic occurs on the topmost item, it should be sent to every item under the topmost one.

    I try different solutions but can't get it work. Here is my last try in a class derived from QGraphicsScene:

    Qt Code:
    1. bool myScene::event(QEvent *event)
    2. {
    3. if ( event->type() == QEvent::GraphicsSceneMousePress ) {
    4. me->setModifiers(Qt::ControlModifier);
    5. for ( int i = 0; i < items(me->scenePos()).count(); i++ ){
    6. items(me->scenePos()).at(i)->setFocus(Qt::MouseFocusReason);
    7. mousePressEvent(me);
    8. }
    9. return false;
    10. }
    11. QGraphicsScene::event(event);
    12. return true;
    13. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for any help

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Custom items selection in qgraphicsscene

    Hi, if you want to deliver events I don't know since graphicsitems has no notify(). [dirty: you could inherit QObject in each item, then use notify] But if you only want to select the items why not just use setSelected:

    Qt Code:
    1. bool myScene::event(QEvent *event)
    2. {
    3. if ( event->type() == QEvent::GraphicsSceneMousePress ) {
    4. // test if right or left button is used
    5. for ( int i = 0; i < items(me->scenePos()).count(); i++ ){
    6. items(me->scenePos()).at(i)->setSelected(true); //<--
    7. }
    8. return false;
    9. }
    10. QGraphicsScene::event(event);
    11. return true;
    12. }
    To copy to clipboard, switch view to plain text mode 

    And better cache items(me->scenePos()) instead of performing the "search" in each for-run.

  3. #3
    Join Date
    Oct 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom items selection in qgraphicsscene

    Hello, thank you for replying.

    I have an eventfilter on the items, depending where the clic occurs on the item I move or resize it. So I need to have a mouse event on every item, not only a selection behaviour.

    And I will cache the item before the loop!

  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: Custom items selection in qgraphicsscene

    Still what do u want to achieve with the items below the top item ? What behaviour you want ?
    might be it can be done some other way than modifying the current behaviour of graphics view framework

  5. #5
    Join Date
    Oct 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom items selection in qgraphicsscene

    Yes you are right, there is probably a best way to do what I want.

    So here is what i have:
    I add line items on my scene, if I clic an extremity of the line, I can rotate/resize it and when I clic any other point of the line, I move it around my scene.

    What I want:
    If two lines are contiguous, I'd like that clicking on the intersection of the two lines permit to rotate/resize the 2 lines at a time.

    If you have a good way to do this...

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Custom items selection in qgraphicsscene

    Hi,

    I just come across QCoreApplication::postEvent ( QObject * receiver, QEvent * event ). May it help you.

    Lykurg

  7. #7
    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: Custom items selection in qgraphicsscene

    There was a FotoWall example on Qt-apps.org . Search and read the code.
    It had features of resizing and rotating graphics item

    As for ur case, moving is not a problem, graphics item can move in a scene.. you only need to enable flags for it
    as for rotating, the fotowall example might help u

  8. #8
    Join Date
    Oct 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom items selection in qgraphicsscene

    Hi, thanks for replies!

    I can't use QCoreApplication::postEvent ( QObject * receiver, QEvent * event ) since QGraphicsItem does not herites from QObject.

    I will take a look at Fotowall, but I have already the resizing, rotating feature working on my items, what I want is to apply this feature at many items at the same time if items are colliding.

    I will try again and let you if I find a solution to my problem.

Similar Threads

  1. How could I save Items on a QGraphicsScene?
    By pinkfrog in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 05:03
  2. QListWidget selection custom painting problem
    By xeento in forum Qt Programming
    Replies: 3
    Last Post: 27th November 2008, 09:49
  3. Adding items to a QGraphicsScene's selection list?
    By mooreaa in forum Qt Programming
    Replies: 2
    Last Post: 1st July 2008, 20:01
  4. Cann't move movable items on custom graphics view
    By wojtekw in forum Qt Programming
    Replies: 2
    Last Post: 3rd March 2008, 21:30
  5. multiple selection of list view items
    By samirg in forum Qt Programming
    Replies: 2
    Last Post: 30th October 2007, 19: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.