Results 1 to 12 of 12

Thread: cursor artifact while grabbing graphics item

  1. #1
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default cursor artifact while grabbing graphics item

    Hi!

    I make an application using QGraphicsItems (Qt 4.5.3), which basically allows the user to draw polygons in a scene/view


    Now, when I grab a vertex, a graphic artifact appears under my cursor (see attached picture). I suspect this is due to either the vertex bounding rect (which is computed in order to be zoom-independant), or to the cursor itself; but i can't figure out what is happening.

    If anyone has a few minutes to spend on my case, the project can be found here :
    project home page on google code

    A Windows executable can be found here :
    Windows executable download


    The artifact appears when i use the [Add Vertex] tool, not when i simply move a vertex with the [Select] tool :S

    I'm sorry if i'm not clear enough, i could try to be more precise if you have questions

    Thank you all
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Thumbs up Re: cursor artifact while grabbing graphics item

    no known bugs with cursor mask or apparented things (hoverevent conflicts, grabbed items weird behavior, etc.) ?

  3. #3
    Join Date
    Sep 2009
    Posts
    36
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: cursor artifact while grabbing graphics item

    Make your svn code compile and I'll give it a try...

  4. #4
    Join Date
    Oct 2008
    Posts
    71
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: cursor artifact while grabbing graphics item

    Quote Originally Posted by soxs060389 View Post
    Make your svn code compile and I'll give it a try...
    I second that - does not compile on mac.

    As for artifacts... I had similar issues with my graphics app. In my app I created a few custom QGraphicsItems derived classes, which at first were giving me a lot of pain. The rule of thumb is not do paint outside of the region limited with the path returned by the QGraphicsItem::shape() function. While drawing QGraphicsScene/View does not bother to erase/redraw whatever was outside of that region. So if you do paint outside - all this stuff will most likely keep stacking up every time your item is redrawn, which will lead to a "leak of ink" in the form of artifacts.

    Hope that helps.

  5. #5
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: cursor artifact while grabbing graphics item

    Quote Originally Posted by soxs060389 View Post
    Make your svn code compile and I'll give it a try...
    i forgot to precise i'm linking statically (so I don't have to make an installer). This might be the problem. File to change are TSPLib.pro and TSPViewer.pro


    Quote Originally Posted by psih128
    As for artifacts... I had similar issues with my graphics app. In my app I created a few custom QGraphicsItems derived classes, which at first were giving me a lot of pain. The rule of thumb is not do paint outside of the region limited with the path returned by the QGraphicsItem::shape() function. While drawing QGraphicsScene/View does not bother to erase/redraw whatever was outside of that region. So if you do paint outside - all this stuff will most likely keep stacking up every time your item is redrawn, which will lead to a "leak of ink" in the form of artifacts.

    Hope that helps.
    Thank you for feedback, i'll take a look at this

  6. #6
    Join Date
    Sep 2009
    Posts
    36
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: cursor artifact while grabbing graphics item

    I am comiling on Fedora / Linux, and I rather prefer dynamic linking, and if you want to share your code with dev's it's much easier to dynamically link it, makt it link statically for a release version. Just a thought.
    Sincerely

  7. #7
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: cursor artifact while grabbing graphics item

    indeed you are absolutely right. i committed changes and compiled without any problem with QtCreator yesterday, so from now the shared-build version is available on svn.

    Back to my problem, i considered what psih128 said, but unfortunately i can not see where the QGraphicsItems would be a problem.

    Here is the code which determines my item's rect (full code here) :

    Qt Code:
    1. void
    2. TSPVertexItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
    3. {
    4. qreal lod = option->levelOfDetail ;
    5. double radius = 2.0/lod ;
    6.  
    7. m_rect.setRect( -radius, -radius, 2*radius, 2*radius ) ; // <- HERE
    8.  
    9. painter->save();
    10. painter->setRenderHint(QPainter::Antialiasing);
    11.  
    12. QPen _pen ;
    13. _pen.setCosmetic(true) ;
    14.  
    15. // setColor on QPen ...
    16.  
    17. painter->setPen( _pen ) ;
    18. painter->drawRect(m_rect) ;
    19.  
    20. painter->restore();
    21. }
    To copy to clipboard, switch view to plain text mode 

    And here is my QGraphicsItem::shape() function

    Qt Code:
    1. TSPVertexItem::shape() const
    2. {
    3. path.addRect( m_rect );
    4. return path;
    5. }
    To copy to clipboard, switch view to plain text mode 

    This said, the artifact seems to be size-constant in scene coordinates (i.e : if i zoom in, artifact is bigger and vice-versa). I don't use to insist like this, but here and now I'm stuck; any comment/idea will be gracefully accepted

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: cursor artifact while grabbing graphics item

    Why do you change m_rect inside your paint() method? You shouldn't do that. If you want your item to have the same size regardless of the zoom factor, set the ItemIgnoresTransformations flag on your item instead.
    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.


  9. #9
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: cursor artifact while grabbing graphics item

    thank you for this comment wyzota (tried this once but somehow it bugged)

    I applied your idea and it's better now, though not resolved : there are no more ink leak but there still remains a black rectangle under cursor when using the [Add vertex] tool... I'll explore other possibilities tonight :/

  10. #10
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: cursor artifact while grabbing graphics item

    Found it...

    Problem came from the TSPEdgeItem class : when i don't set the painter antialising render hint, artifact disappears.
    On one hand i'm happy because i found where bug comes from, on the other hand it's disapointing 'cause i don't really understand the workaround, plus i can't use Antialiasing to render this item...


    thank you for your attention

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    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: cursor artifact while grabbing graphics item

    You need to adjust boundingRect() of your item to compensate for anti-aliasing. Just increase the bounding rect (and shape) by 1 in each direction (meaning 0.5 from each side of the rectangle).
    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.


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

    totem (9th January 2010)

  13. #12
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: cursor artifact while grabbing graphics item

    i resolved the bug considering your answer : i detected where and when my edge-items had zero-length (destPoint==sourcePoint) - which was the cause of all this - and avoid it to be drawn
    thank you

Similar Threads

  1. How do you embed a widget in a graphics item?
    By technoViking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 06:09
  2. how to you send signals to a graphics item?
    By technoViking in forum Qt Programming
    Replies: 4
    Last Post: 6th November 2009, 19:40
  3. Graphics item position after drag
    By Miihkali in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2009, 10:01
  4. Graphics View - Scene & Item hierarchy
    By mooreaa in forum Qt Programming
    Replies: 0
    Last Post: 29th June 2008, 23:49
  5. Reimplementing The MousePressEvent for Graphics Item
    By ashishrai in forum Qt Programming
    Replies: 3
    Last Post: 25th May 2008, 20:11

Tags for this Thread

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.