Results 1 to 11 of 11

Thread: Creating a pixmap

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Creating a pixmap

    Hi guys,

    How to draw a polygon like:
    Qt Code:
    1. QPolygonF polygon;
    2. polygon<<QPointF(-10.0,-10.0);
    3. polygon<<QPointF(-5.0,10.0);
    4. polygon<<QPointF(0.0,5.0);
    5. polygon<<QPointF(5,-10.0);
    6. // It is important that the polygon contains negative lat/long values
    To copy to clipboard, switch view to plain text mode 

    Thanks,

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a pixmap

    I am drawing complex graphics scene background (containing hundreds thousands of polygons) and would like to first create a pixmap containing that filled polygons(with solid color, no edges) and then, I believe, it would redraw the background faster.

    That's why I need to draw this kind of polygons.

    Maybe it's very simple. Excuse me if it is trivial.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  3. #3
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a pixmap

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main()
    4. {
    5. QPolygonF polygon;
    6. polygon<<QPointF(-10.0,-10.0);
    7. polygon<<QPointF(-5.0,10.0);
    8. polygon<<QPointF(0.0,5.0);
    9. polygon<<QPointF(5,-10.0);
    10.  
    11. QImage image(360, 360, QImage::Format_ARGB32);
    12. image.fill(Qt::transparent);
    13. QPainter painter(&image);
    14. painter.setPen(Qt::NoPen);
    15. painter.setBrush(Qt::red);
    16. painter.translate(180,180);
    17. painter.drawPolygon(polygon);
    18. image.save("test.png");
    19. }
    To copy to clipboard, switch view to plain text mode 
    It works the same with QPixmap.

  4. #4
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a pixmap

    Simple is that.

    Thanks
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  5. #5
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a pixmap

    Hi,

    A bit different question, also connected with pixmaps.
    What if I want to draw polygons( let's say 5000) inside one pixel? Mose of the time I have to draw a lot of polygons inside 1 degree of a coordinates, so polygon points only different by 0.001. For example, drawing a polygonF:
    A) -32.333 -170.555
    B) -32,334 - 170.556
    C) -32,534 - 170, 777

    etc


    Thanks
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #6
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a pixmap

    I'm sorry, but what was the question? Do you want to avoid drawing the polygons when they are smaller than a pixel?

  7. #7
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a pixmap

    THe question is:

    How to avoid drawing thousands of polygon in the QGraphicsScene when in Qt 4.4.1 polygon clipping is pretty slow. I am looking for any solution that would speed up drawing of that polygons; As this polygons do not have edges and are filled with solid color, I thought about drawing them to a pixmap or any other device and then drawing pixmap in the background what would no involve polygon clipping.

    Do you have any ideas, how to do this ?

    Most of the polygons coordinates are inside one degreee, like:
    -32.544
    -32.543
    -32 634
    -32 533;
    etc.

    Thank you for any help, I apologize if the problem is trivial.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  8. #8
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a pixmap

    I definitely wouldn't say the problem is trivial.
    You could reimplement QGraphicsPolygonItem:: paint in a subclass and check QStyleOptionGraphicsItem:: levelOfDetail and then decide whether to call the base implementaion or drawing a simpler shape(or none at all).

    See 40000 chips

  9. #9
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a pixmap

    Good ideas, but I am almost sure it will not help.
    It would if I was working mostly with items, but the background/foreground drawing is the issue.
    Just to add sth, I do not draw QGraphicsPolygonItem, but use painter for the background to draw polygons: (painter->drawPolygon(...)). etc.

    Polygon clipping is slow, and this is the week point of drawing. I am also thinking about moving clipping calculation to another thread; this might help. But these are just ideas.


    Any other ideas, anyone?

    Kacper
    Last edited by maverick_pol; 8th October 2008 at 18:30.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  10. #10
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a pixmap

    Which begs the question: Why don't you use items for drawing the background(a map I assume).
    The only other alternative I can think of is preprocessing the polygons, sort of like mipmapping. Then you would have a differently complex for each zoom level.

  11. #11
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Creating a pixmap

    I have a lot of things being drawn in the foreground/background/item layer.
    I just have an idea of doing sth like this;
    When the library is being drawn for the first time (whole lib is visible) is ok. What about grabbing the viewport background to an image when whole libs is visible, and when the user zoom into the lib I can cut a part of that image and draw the needed part of the image.
    Ok.... maybe it will work...


    Kacper

    P.S

    Thank you very much spud for throwing your ideas!!!! : )

    [EDITED]
    The idea connected with using QPixmap to grabbing the viewport() is naive.
    If you have a lot of items and the order of drawing different elements is important it is not the best idea. Too complicated to achieve the result.
    Last edited by maverick_pol; 8th October 2008 at 20:17.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

Similar Threads

  1. Performance problems with small pixmap
    By RThaden in forum Qt Programming
    Replies: 4
    Last Post: 9th July 2008, 15:14
  2. finding maximum scaling of a pixmap
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 31st March 2008, 14:32
  3. QWizard and banner pixmap
    By desch in forum Qt Programming
    Replies: 8
    Last Post: 7th January 2008, 10:28
  4. empty pixmap as a QLabel
    By tommy in forum Qt Programming
    Replies: 16
    Last Post: 11th December 2007, 21:15
  5. Creating a Pixmap out of an array of data
    By toratora in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 19:00

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.