Results 1 to 11 of 11

Thread: QGraphicsItem selection trouble

  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 QGraphicsItem selection trouble

    Hi,

    I have a QGraphicsItem object called SearchAreaItem which has a shape just like ellipse. This ellipse is formed by short lines which are also QGraphicsItem called LineItem. When I hover the mouse over one of those lines, the line becomes red( because of the way I implemented). However, the problem is; I want the whole shape to be red - not only the line I'm currently on.

    How can I get over this problem?

    Thanks in advance

  2. #2
    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: QGraphicsItem selection trouble

    set a common flag in header

    update() the paint() function when hover enter event occurs with a flag set to 1
    and update() the paint() function when hover leave event occurs with flag set to 0

    in paint()
    if(flag == 1)
    setBrush(rect(), color)
    "Behind every great fortune lies a crime" - Balzac

  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: QGraphicsItem selection trouble

    Hi again,

    you mean should I implement these in the SearchAreaItem(the parent). Moreover, if it is, I should take care of each line in the paint method ?

    Plus, are you sure there is a need for hoverEnterEvent... since it seems paint() of SearchAreaItem can handle it.
    Last edited by zgulser; 12th August 2009 at 12:07.

  4. #4
    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: QGraphicsItem selection trouble

    i mean
    in the graphicsItem:aint() function of SearchAreaItem ...

    are u not painting your SearchAreaItem ..? if so u got the whole control of line ..
    "Behind every great fortune lies a crime" - Balzac

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

    zgulser (13th August 2009)

  6. #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: QGraphicsItem selection trouble

    yes, I do not paint in the SearchAreaItem. that's the problematic case already. But I want to control the not the lines but the whole shape formed by these lines.

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

    Default Re: QGraphicsItem selection trouble

    So access the rest of the lines and mark them to be highlighted. You surely have pointers to those objects somewhere so that shouldn't be a problem.
    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.


  8. #7
    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: QGraphicsItem selection trouble

    I solved the problem. Thanks for your help.

    But, I've come with a new one. I create SearchAreaItem as an ItemGroup and put the LineItems into it. What I want to achieve is to make the SearchAreaItem act as the only item when I perform movement operation. But it confused about the shape() function. In my LineItem class I implement the shape() for more precise mouse operations. In addition to that reimplementation of shape(), I also reimplement it in SearchAreaItem. So what's the deal here? Only one proper shape will be sufficient? Is there any extra work needed for grouping items out of adding the group to the scene and adding the items to that group?

    Thanks in advance!

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

    Default Re: QGraphicsItem selection trouble

    No, there is nothing more required apart from creating the group. Unfortunately your description is not clear enough to understand what your problem is. Providing a piece of code would be helpful.
    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.


  10. #9
    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: QGraphicsItem selection trouble

    I would wish to send a bit but I'm not allowed:/.

    Anyway, I'm trying my best to explain it once.

    I have many LineItems which are created and form an ellipse inside another item group called SearchAreaItem. Futhermore, each LineItem has a shape() function for more efficiency(I assume you've seen the reason already). Now, what I really want to do is treat this SearchAreaItem as the composite item. Don't want to deal with LineItem's created inside it when the mouse hover over click operations take place. That's why I designed the SeachAreaItem as an item group.

    Now I want to ask, what the main usage of setHandlesChildEvents method?

    and, although I didn't implement the itemChange() method, I'm now able to drag-drop my SearchAreaItem( the ellipse) by only setting movable flag. Isn't it a bit odd?

  11. #10
    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: QGraphicsItem selection trouble

    Now I want to ask, what the main usage of setHandlesChildEvents method?
    itemGroup->setHandlesChildEvents (false ); will make all the members in the group independent ...

    without setting this .. the focus will be on whole .. mouse click is common everywhere to the group members ..
    "Behind every great fortune lies a crime" - Balzac

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

    zgulser (13th August 2009)

  13. #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: QGraphicsItem selection trouble

    ... what about the shape() function?

Similar Threads

  1. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  2. Replies: 1
    Last Post: 18th November 2009, 23:21
  3. QGraphicsItem selection
    By navi1084 in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2009, 14:57
  4. selection of QGraphicsItem
    By navi1084 in forum Qt Programming
    Replies: 6
    Last Post: 23rd July 2009, 06:33
  5. Replies: 1
    Last Post: 25th February 2009, 00:34

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.