Results 1 to 6 of 6

Thread: QGraphicsItem-QGraphicsScene

  1. #1
    Join Date
    Jul 2007
    Posts
    104
    Thanks
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default QGraphicsItem-QGraphicsScene

    I created a form using QGraphics classes.On them there are pictures.How can I scale them by using keyboard ?
    (For scaling I am using QTimeLine class -scale() function etc.)

  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: QGraphicsItem-QGraphicsScene

    If you want to scale only the selected image( that item has to have the selectable flag ), independently of the other images, then you can catch keyboard event with QGraphicsItem::keyPressEvent.

    If you want to scale the entire scene at the same time, then you can catch key presses with QGraphicsScene::keyPressEvent.

    Please note that you have to subclass QGraphicsItem/QGraphicsScene and override keyPressEvent in order to be able to get key presses.

    Regards

  3. The following user says thank you to marcel for this useful post:

    hgedek (4th August 2007)

  4. #3
    Join Date
    Jul 2007
    Posts
    104
    Thanks
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem-QGraphicsScene

    I think I will use QGraphicsItem.On scene I have 6 image.And using keyboard I will pass one to another.Then pressed anothet button I will activate it.(Like Nokia menu!)

  5. #4
    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: QGraphicsItem-QGraphicsScene


    To move with the keyboard from one item to another in a scene you will have to override QGraphicsScene::keyPressEvent and catch the arrow key presses there.
    The default behavior for the arrow keys is none( the view will scroll actually ).

    Regards

  6. The following user says thank you to marcel for this useful post:

    hgedek (4th August 2007)

  7. #5
    Join Date
    Jul 2007
    Posts
    104
    Thanks
    22
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem-QGraphicsScene

    Ok.I read scene::keyPressEvent.But I couldnt understand how to do.setFocus or setFocusItem
    functions are used?Or how to do?

    infos:
    items are scaling translating etc in its Item class.This works by hover event.

  8. #6
    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: QGraphicsItem-QGraphicsScene

    I think QGraphicsItem::setSelected(true) should do it.
    But, anyway, if the next item that you select does not have focus, you also should call setFocusItem. Make sure that all the items have the flags: ItemIsSelectable and ItemIsFocusable.

    Regards

  9. The following user says thank you to marcel for this useful post:

    hgedek (4th August 2007)

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 20:50
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. Replies: 4
    Last Post: 11th July 2007, 04:21
  4. When to use QGraphicsScene or QWidget
    By fossill in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2007, 23:58
  5. (QT4.2-RC1) QGraphicsScene QGraphicsView QGraphicsItem
    By antonio.r.tome in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 10:56

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.