Results 1 to 3 of 3

Thread: Stippled Pattern when Painting with mouse/tablet

  1. #1
    Join Date
    Mar 2014
    Location
    San Diego
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Stippled Pattern when Painting with mouse/tablet

    Hello all,

    I am experience a problem where if I try to draw with pen/tablet input, the widget will draw a line along with circles at points periodically. Such as the following:
    problem.png
    The code(in context of QTabletEvent, QMouseEvent is coded the same way):
    Qt Code:
    1. bool deviceDown = false;
    2. QPoint drawPath[3];
    3.  
    4. void Editor::TabletEvent(QTabletEvent* event)
    5. {
    6. if(event->type() == QEvent::TabletPress)
    7. {
    8. deviceDown = true;
    9. drawPath[2] = drawPath[1] = drawPath[0] = event->pos();
    10. }
    11. if(event->type() == QEvent::TabletRelease)
    12. {
    13. if(deviceDown == true){deviceDown = false;}
    14. }
    15.  
    16. if(event->type() == QEvent::TabletMove)
    17. {
    18. drawPath[2] = drawPath[1];
    19. drawPath[1] = drawPath[0];
    20. drawPath[0] = event->pos();
    21.  
    22. /* DRAW CODE - Commented out due to actual code residing in another class/function.
    23.   QPainter painter(&pixmap);
    24.   painter.drawLine(drawPath[1], event->pos());
    25.   */
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    I have attempted to use a single point as the last known point, but that failed. Using a QPoint array seams to be the only way to get the widget to draw any lines correctly.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Stippled Pattern when Painting with mouse/tablet

    You paint a translucent (alpha < 1.0) line from A to B, then B to C, C to D etc. The point B is painted twice, once for each line it is part of. The result is that the brush area on top of point B is now darker. Same goes for C etc.

    Options:
    • Accumulate points from press to release and then draw a single poly-line (QPainter::drawPolyLine())
    • Accumulate points from press and draw a single polyline onto a transparent overlay image that you then compose with the base image onto the display. When the finger is raised draw the entire polyline into the base image.

  3. #3
    Join Date
    Mar 2014
    Location
    San Diego
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Stippled Pattern when Painting with mouse/tablet

    Alright I'll try that out. Will the same method work if I invoke "painter.drawPixmap()" or "painter.drawEllipse"?

Similar Threads

  1. Replies: 1
    Last Post: 30th April 2013, 11:41
  2. Painting the mouse trace in a QGraphicsItem
    By xtraction in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2013, 10:08
  3. Dymamic Painting outside paintEvent on mouse movement in QT4
    By shivam.priyadarshi in forum Qt Programming
    Replies: 7
    Last Post: 30th June 2012, 07:07
  4. How to make painting on mouse move?
    By athulms in forum Newbie
    Replies: 1
    Last Post: 3rd November 2011, 09:07
  5. Replies: 2
    Last Post: 1st January 2011, 17:00

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.