Results 1 to 10 of 10

Thread: Problem painting lines

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Problem painting lines

    Hi,

    I'd like to paint, into a scene, some lines connected with one of the Join Style available in QPen definition.

    the next code:

    Qt Code:
    1. QPen myPen(brush,10,Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
    2.  
    3. my_scene->addLine(QLineF(QPointF(0,0), QPointF(100, 0)), myPen);
    4. my_scene->addLine(QLineF(QPointF(100,0), QPointF(100, 100)), myPen);
    To copy to clipboard, switch view to plain text mode 

    doesn't show that join style (logically). So I started with QGraphicsPathItem ----> QPainterPath, where the function "addQLineF" does not exist.

    How I can paint, in a scene, my lines joined with the pen's join style?

    thanks!

  2. #2
    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: Problem painting lines

    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.


  3. #3
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Problem painting lines

    I'm working with a scene (I need to create items as well)... will I have any incompatibility if I start to paint forms in screen with a QPainter? Will they work properly as the items inside the scene if I start to edit the views, use zooms and so on?

  4. #4
    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: Problem painting lines

    You can create a custom item if you need to and draw inside its proper drawing routine. But you can use the painter path item with the first method I suggested.
    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.


  5. #5
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Problem painting lines

    Sorry, I'm not talking clearly:

    What I have, right now, it's a Graphics View "promoted to" my own "view class", in order to control all the events. Inside, I have some clasess, some inherits from qGraphicsItemLine, other from QGraphicsItemGroup... it depends what do I need to do with them.

    I also have an scene added to myView.cpp. From the view code I control, for example, the zoom with the mouse wheel.

    But I'm having troubles when I try to draw the object which inherits from QGraphicsItemGroup, it will have a polygon form but I don't know if the polygon will interact properly with the graphics view and, also, if I create a polygon item on the top the events of the itemgroup could be lost (because the events, like "on click", of the itemPolygon will be called instead). That can be solved... but I don't want to have more items when I just want to paint a polygon.

    So, after the explanation my question is: if I paint some forms from qpainter, in my scene and view, will they react properly when I interact and change the views, like the items do? in the documentation seems like it's. somehow, divided, "qpaint object" in one side and "scene, views and items" on the other. And QPainter is connected to the widget, not connected to the view...

    But, on the other hand, I just want to have a non-event-oriented item.
    Last edited by jano_alex_es; 25th June 2009 at 15:11.

  6. #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: Problem painting lines

    No, they won't. If you use Graphics View, use items only. Unless of course you are really convinced you know what you are doing.
    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.


  7. #7
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Problem painting lines

    QPainterPath::lineTo() and QPainter::drawLines() in general.
    I will need to have the lines sorted in the array (drawLines) if I want to have the joins, won't I?

  8. #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: Problem painting lines

    Yes, the lines have to connect.
    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. The following user says thank you to wysota for this useful post:

    jano_alex_es (29th June 2009)

  10. #9
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Problem painting lines

    Does it work with multiple joins? like, for instance:



    If I add the red line just after the black one in the vector, I suppose the join just will be done between those two and nothing will be done if I try to connect with the blue one.

    If so, any way to "create a join" between three lines?

    thanks!

  11. #10
    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: Problem painting lines

    You can paint the red line again the other way (so that you paint two red lines instead of one) to have a "sequence" with the blue one.
    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:

    jano_alex_es (1st July 2009)

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  3. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  4. Painting lines
    By therealjag in forum Newbie
    Replies: 34
    Last Post: 23rd March 2006, 22:43
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.