Results 1 to 3 of 3

Thread: Strange Painter behaviour

  1. #1
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Strange Painter behaviour

    Hi Everyone,

    I seem to have some odd behaviour I can't explain.
    Here is my code:
    Qt Code:
    1. void ScribbleArea::drawGrid()
    2. {
    3. QPainter painter(&image);
    4. painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
    5. Qt::RoundJoin));
    6.  
    7. for(int y=0; y<image.height(); y+=gridSize)
    8. for(int x=0; x<image.width(); x+=gridSize)
    9. painter.drawPoint(x,y);
    10. }
    11.  
    12. void ScribbleArea::drawPolygon()
    13. {
    14. QPainter painter(&image);
    15. painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
    16. Qt::RoundJoin));
    17.  
    18. #if 0
    19. drawGrid();
    20. #else
    21. for(int y=0; y<image.height(); y+=gridSize)
    22. for(int x=0; x<image.width(); x+=gridSize)
    23. painter.drawPoint(x,y);
    24. #endif
    25.  
    26. painter.drawLine(myPolygon);
    27. modified = true;
    28. }
    29.  
    30. void ScribbleArea::paintEvent(QPaintEvent * /* event */)
    31. {
    32. QPainter painter(this);
    33. painter.drawImage(QPoint(0, 0), image);
    34. }
    To copy to clipboard, switch view to plain text mode 

    Please note that this code copied from the scribble example!
    Anyway I wanted to add my own grid drawing routine
    Which seems to work just fine when called seperatly.

    However if drawPolygon() calls drawGrid() the grid never shows
    up. I do get to the routine but I simply don't see the grid drawn.
    If I copy the routine into the drawPolygon() (see the #if 0)
    then it does work.
    Can someone explain this?

    Regards

    Otto
    Attached Files Attached Files

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Strange Painter behaviour

    I suspect it has something to do with that you initialize 2 parallel painters on the image.
    Does it work if you use the same painter, like this?
    Qt Code:
    1. void ScribbleArea::drawGrid(QPainter* painter)
    2. {
    3. for(int y=0; y<image.height(); y+=gridSize)
    4. for(int x=0; x<image.width(); x+=gridSize)
    5. painter->drawPoint(x,y);
    6. }
    7.  
    8. void ScribbleArea::drawPolygon()
    9. {
    10. QPainter painter(&image);
    11. ...
    12. drawGrid(&painter);
    13. ...
    14. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Sep 2006
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Strange Painter behaviour

    Yes, that was what I also suspected.
    However after the modifications the behaviour was
    identical as before.

    It really looks like it doesn't like to call any other methods
    while being in drawPolygon().
    Otto Meijer
    email: otto.meijer@synopsys.com

Similar Threads

  1. very strange behaviour
    By regix in forum Qt Programming
    Replies: 23
    Last Post: 20th July 2006, 17:38
  2. How to manage QPainter?
    By Caius Aérobus in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 13:20
  3. Painter not active!
    By Caius Aérobus in forum Qt Programming
    Replies: 7
    Last Post: 30th March 2006, 15:44
  4. Replies: 1
    Last Post: 26th February 2006, 05:52
  5. [Qt 4.1] Strange behaviour with QTableView
    By fane in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 06:17

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.