Results 1 to 2 of 2

Thread: QPainter Fails to Paint

  1. #1
    Join Date
    Apr 2016
    Location
    Tasmania Australia
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default QPainter Fails to Paint

    Good Morning All,

    My app deals with burrowing down to the R G B pixel data in successive video frames. The frame analysis takes place in a dialog where method ShowFrame renders a zoomed QPixmap to screen.

    My problem is I cannot get the QPainter to zoom the pixmap.
    Qt Code:
    1. void IconDialog::ShowFrame(QString aFrameNm, int Zoom)
    2. {
    3. FrameNm = aFrameNm;
    4. scene->clear();
    5. Frame.load(aFrameNm);
    6. scene->setSceneRect(Frame.rect());
    7. QPixmap pixmap = QPixmap::fromImage(Frame);
    8. if (Zoom > 1) {
    9. QRectF sr = pixmap.rect(); //source rectangle
    10. int w = qRound(sr.width()/Zoom);
    11. int h = qRound(sr.height()/Zoom);
    12. QRectF tr; //target rectangle
    13. tr.setX(sr.width()-w);
    14. tr.setY(sr.height()-h);
    15. tr.setWidth(w);
    16. tr.setHeight(h);
    17. if (p.begin(this)) {
    18. p.drawPixmap(tr, pixmap, sr);
    19. p.end();
    20. }
    21. else {
    22. QMessageBox::information(0, "Error IconDialog", "Statement p.begin(this) failed, I don't know why.");
    23. }
    24. }
    25. item = new QGraphicsPixmapItem(pixmap);
    26. scene->addItem(item);
    27. ui->FrameGV->show();
    28. }
    To copy to clipboard, switch view to plain text mode 
    What ever I try results in activating the QMessageBox, I cannot find a "last error" or a reason for failure.
    I have followed the usual procedures to resolve the issue but without success.

    I believe my code is at fault, I have missed something, but what?

    Hope you can help.

    Thank you.

    Regards
    Glen

  2. #2
    Join Date
    Apr 2016
    Location
    Tasmania Australia
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPainter Fails to Paint

    I have found the errors I had made in the posted code (nothing like a good nights sleep).

    Correction 1: Edit line 19 to read "if (p.begin(&pixmap)) {" that got painter working which exposed another error with Source and Target rectangles doing the wrong thing.

    Correction2: Transpose the use of "sr" and "tr".

    Sorry to have troubled you.

    Regards
    Glen

    PS How do I mark this thread SOLVED?

Similar Threads

  1. Make QPainter paint above all widgets
    By Grzyboo in forum Newbie
    Replies: 5
    Last Post: 3rd November 2015, 19:37
  2. How to paint unicode surrogate pairs using QPainter?
    By BobWu in forum Qt Programming
    Replies: 5
    Last Post: 2nd January 2013, 17:52
  3. QPainter immediate drawing outside paint event
    By sfcheng77 in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2011, 06:39
  4. QPainter::begin: Cannot paint on a null pixmap
    By sabeesh in forum Qt Programming
    Replies: 5
    Last Post: 27th July 2010, 18:03
  5. How to paint (QPainter) on a label ?
    By d@nyal in forum Newbie
    Replies: 1
    Last Post: 29th May 2010, 18:39

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.