Results 1 to 5 of 5

Thread: Create Thought Balloons

  1. #1
    Join Date
    Jan 2007
    Location
    Rome
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Cool Create Thought Balloons

    Hi All !

    I would like to create some vector graphics ballons that can be customized by the user (changing the scale factors and position of the stem.

    Internally I use QPainter to draw all the balloons stuff including the balloons shapes.

    For every type of balloon I create, on the fly, a QPainterPath from an union of several polygons.

    I try to do something like this with a strange results that probably depends from the painterpath position:



    The code (very straightfoward and not optimize) is the following:

    Qt Code:
    1. QPolygonF Balloon::getSoftPolygon()
    2. {
    3. int w = m_rect.width();
    4. int h = m_rect.height();
    5.  
    6. QPoint center = m_rect.center()-QPoint(w*0.25,h*0.25);
    7. QRect smallRect(center.x(),center.y(),w*0.5,h*0.5);
    8.  
    9. s2.addEllipse(smallRect.translated(w*0.2,0));
    10.  
    11. s3.addEllipse(smallRect.translated(-w*0.2,0));
    12.  
    13. s4.addEllipse(smallRect.translated(w*0.1,-h*0.2));
    14.  
    15. s5.addEllipse(smallRect.translated(-w*0.1,-h*0.2));
    16.  
    17. s6.addEllipse(smallRect.translated(w*0.1,h*0.2));
    18.  
    19. s7.addEllipse(smallRect.translated(-w*0.1,h*0.2));
    20.  
    21. QPolygonF p = s2.united(s3).united(s4).united(s5).united(s6).united(s7).toFillPolygon();
    22. return p;
    23. }
    To copy to clipboard, switch view to plain text mode 

    Then in the paintEvent...

    Qt Code:
    1. QPolygonF stemPolygon = getStemPolygon();
    2.  
    3. QPainterPath overallShape = QPainterPath();
    4. overallShape.addPolygon(getSoftPolygon().united(stemPolygon));
    To copy to clipboard, switch view to plain text mode 

    Probably exist a more simple way to create a "soft" balloon using QPainterPath.
    Any suggestions and different solution are welcome !!

    Bye, bye !

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Create Thought Balloons

    I try to do something like this with a strange results that probably depends from the painterpath position:
    I take you mean the line that goes through the balloons...

    Do you call QPainterPath::closeSubpath () somewhere?
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2007
    Location
    Rome
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Create Thought Balloons

    No, I never call closeSubpath.
    The problem is exactly the lines that start from some ellipse (circle) of the stem.
    I try to add some closeSubpath calls but the problem still remains.

    To create the stem polygon I use the following code block :

    Qt Code:
    1. QPolygonF polygon;
    2. p1.addEllipse(QRect(apex.x()-5,apex.y()-20,10,10));
    3. p1.addEllipse(QRect(apex.x()-10,apex.y()-45,20,20));
    4. p1.addEllipse(QRect(apex.x()-20,apex.y()-90,30,30));
    5.  
    6. QList<QPolygonF> list = p1.toFillPolygons();
    7. for(int i=0;i<list.size();i++)
    8. {
    9. polygon = polygon.united(list.at(i));
    10. }
    11. ...
    12. ...
    13. return polygon;
    To copy to clipboard, switch view to plain text mode 

    Any suggestions ?

  4. #4
    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: Create Thought Balloons

    I think that if you unite shapes, they get closed and that's where the line comes from. I'd say you should use a simple SVG file instead of rendering those paths. It would give you much more flexibility. If not, then just don't unite those polygons and see if the line is still there.

  5. #5
    Join Date
    Jan 2007
    Location
    Rome
    Posts
    30
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Create Thought Balloons

    I surely prefer to use SVG but I need to modify the balloon stem so I cannot modify very easily an svg file.

    Probably the best solution is to use directly a lot of cubicTo calls (Bezier Curve) in order to create the right shape. Is not so easy to manage a lot of points and make it linked with the object dimension.. but I'll try.

    I think that will be very useful to create a sort of editor that allows to draw curves, edit control points and export the values with the possibility to add some kind of constraint, etc.

    If I have some free time I will create something like that !

    Angelo

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.