Results 1 to 3 of 3

Thread: Strange behaviour of QPainter...

  1. #1
    Join Date
    Sep 2007
    Posts
    31
    Thanked 1 Time in 1 Post

    Default Strange behaviour of QPainter...

    I'm missing something:
    In the following code, I must display a QMessageBox to get a correct QPixmap (with a chart in it).
    Do you know what's the problem?

    Thanks.
    Regards,
    Oscar

    Qt Code:
    1. QPixmap MyExport::drawPie(int size, QList<int> valueList, QList<QString> colorList) {
    2.  
    3. QPixmap qPixmap(size,size);
    4. QPainter *myQPainter = new QPainter(&qPixmap);
    5.  
    6. myQPainter->setBrush(QBrush(QColor(245,245,245)));
    7. myQPainter->drawRect(0,0,size,size);
    8.  
    9. double startAngle = 0.0;
    10. double totalValue; foreach(int value, valueList) totalValue += value;
    11.  
    12. for (int i=0; i<valueList.size(); i++) {
    13. if (valueList[i] > 0.0) {
    14. double angle = 360*valueList[i]/totalValue;
    15. QColor color = QColor(colorList[i]);
    16. myQPainter->setBrush(QBrush(color));
    17. myQPainter->drawPie(0, 0, size-2, size-2, int(startAngle*16), int(angle*16));
    18. startAngle += angle;
    19. }
    20. }
    21. delete myQPainter;
    22.  
    23. QMessageBox::information(NULL, QString::fromUtf8("Warn"),
    24. QString::fromUtf8("This messagebox must be called to make this example function"),
    25. QString::fromUtf8("Quitter"));
    26. return qPixmap;
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2007
    Posts
    31
    Thanked 1 Time in 1 Post

    Default Re: Strange behaviour of QPainter...

    This code works fine on Linux but generates an empty pixmap on windows (unless I display a messagebox at the end of processing!)

    It sounds like a bug...

    Regards,
    Oscar

  3. #3
    Join Date
    Sep 2007
    Posts
    31
    Thanked 1 Time in 1 Post

    Default Re: Strange behaviour of QPainter...

    Well, now it's working when I create a class Pie subclassing
    a QWidget and draw the pie in the paintEvent(QPaintEvent *event) method.

    The Pie class is used like this:

    Qt Code:
    1. Pie *pie = new Pie(valueList, colorList, 150);
    2. QImage image; image = QPixmap::grabWidget(pie).toImage();^M
    3. image = image.copy(1,1,image.width()-1,image.height()-1);^M
    4. qPainter->drawImage(xPos, yPos, image);
    To copy to clipboard, switch view to plain text mode 

    I still think there's a problem in Windows release of Qt when using QPainter...

    Regards,
    Oscar

Similar Threads

  1. qinputdialog strange behaviour
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2008, 19:29
  2. Strange Painter behaviour
    By cwomeijer in forum Qt Programming
    Replies: 2
    Last Post: 4th September 2006, 20:52
  3. very strange behaviour
    By regix in forum Qt Programming
    Replies: 23
    Last Post: 20th July 2006, 17:38
  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.