Results 1 to 2 of 2

Thread: Problem with QPainter

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Posts
    4
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Problem with QPainter

    Hi everyone,

    I am using Qpainter to paint on a pixmap by using mouse movements

    The following problems were there -

    1. QPainter::begin: Paint device returned engine == 0, type: 2

    2. While drawing the coordinate system gets screwed up and there is a shift while drawing the lines.

    Here is my part of source code..
    Scaled is the pixmap I scaled to (300,300) after loading the image

    Qt Code:
    1. void MainWindow::mousePressEvent(QMouseEvent *event)
    2. {
    3.  
    4. if (event->button() == Qt::LeftButton) {
    5.  
    6. lastPoint = event->globalPos();
    7. scribbling = true;
    8. }
    9. }
    10.  
    11. void MainWindow::mouseMoveEvent(QMouseEvent *event)
    12. {
    13. if ((event->buttons() & Qt::LeftButton) && scribbling)
    14.  
    15. drawLineTo(event->globalPos());
    16. }
    17. void MainWindow::paintEvent(QPaintEvent *event)
    18. {
    19. QPainter painter(&scaled);
    20. QRect dirtyRect = event->rect();
    21. painter.drawPixmap(dirtyRect, scaled, dirtyRect);
    22. }
    23. void MainWindow::drawLineTo(const QPoint &endPoint)
    24. {
    25. QPainter painter(&scaled);
    26. painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap,
    27. Qt::RoundJoin));
    28. //painter.begin(&scaled);
    29. painter.drawLine(lastPoint, endPoint);
    30.  
    31.  
    32. int rad = (myPenWidth / 2) + 2;
    33. update(QRect(lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad));
    34. lastPoint = endPoint;
    35. //painter.end();
    36. }
    37.  
    38. void MainWindow::mouseReleaseEvent(QMouseEvent *event)
    39. {
    40. if (event->button() == Qt::LeftButton && scribbling) {
    41. drawLineTo(event->globalPos());
    42. scribbling = false;
    43. }
    44. ui->Image -> setPixmap (scaled);
    45. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 3rd March 2011 at 13:06. Reason: code tags

Similar Threads

  1. Problem with QPainter
    By vijay_kansal in forum Qt Programming
    Replies: 3
    Last Post: 24th July 2010, 12:55
  2. problem in QPainter::begin
    By wagmare in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2009, 10:31
  3. QPainter problem (a HW issue perhaps?)
    By jonks in forum Qt Programming
    Replies: 10
    Last Post: 10th June 2009, 03:05
  4. Qt 2.3.10 QPainter problem on arm
    By yagabey in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 7th October 2008, 12:29
  5. QT 4.4.0 Upgrade QPainter Problem
    By ChrisReath in forum Qt Programming
    Replies: 4
    Last Post: 13th May 2008, 15:25

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.