Results 1 to 3 of 3

Thread: Implement a selection tool for a QQuickPaintedItem

  1. #1
    Join Date
    Nov 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Question Implement a selection tool for a QQuickPaintedItem

    Hello,
    I want to create a selection tool for scribble program.

    My scribble area is based on a QPainter in a QQuickPaintedItem.
    Now I want to program a feature, that can select a region of the image.

    I like to mark the selected area with a dashed outer line like this:
    selection-adding.gif
    beside a rectangle tool, I want to create a circle tool, too.


    My problem is to get a good performance in my implementation. If the user click or dragging the cursor on the area, I want to give realtime feedback (select the area on the fly) but the framerate is very ugly.
    My circle selection tool looks like:

    Qt Code:
    1. void ImageView::selectPoint(const QPointF & point)
    2. {
    3.  
    4. int radius = 20;
    5. QPainter painter(&image);
    6. QBrush brush;
    7. brush.setStyle(Qt::SolidPattern); // Fix your problem !
    8. brush.setColor(QColor(60,20,20));;
    9. selection.addEllipse(point, radius, radius);
    10. painter.fillPath(selection.simplified(), brush);
    11. QRect currRect = QRect(point.x()- radius, point.y() - radius,radius+radius, radius+radius);
    12.  
    13.  
    14.  
    15. update(currRect);
    16.  
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    I'm also have the problem to draw only the outer line of the selection because I don't clear the image. Is there a option to work with layers (like in a QGraphicsView)?


    Best Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Implement a selection tool for a QQuickPaintedItem

    Quote Originally Posted by sheepy View Post
    I'm also have the problem to draw only the outer line of the selection because I don't clear the image. Is there a option to work with layers (like in a QGraphicsView)?
    Just put one item onto the other, e.g. make the selection item a child of the main item and fill the parent.

    Cheers,
    _

  3. #3
    Join Date
    Nov 2014
    Posts
    6
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Implement a selection tool for a QQuickPaintedItem

    Quote Originally Posted by anda_skoa View Post
    Just put one item onto the other, e.g. make the selection item a child of the main item and fill the parent.
    _
    Thank you, this works for me!
    drawing the path is now okay, but when drawing the outer path (with QPainterPath::simplified () / QPainterPath::union() ) the performance is worse.
    Is there another way, so I can merge different paths on the fly?
    Last edited by sheepy; 3rd December 2014 at 17:11. Reason: add union

Similar Threads

  1. implement c++ in qml
    By askatuak in forum Qt Quick
    Replies: 9
    Last Post: 8th October 2013, 08:31
  2. what is the best way to implement ?
    By david_itay in forum Newbie
    Replies: 1
    Last Post: 8th August 2012, 22:10
  3. How to implement transparent pencil tool in Qt?
    By liuyanghejerry in forum Qt Programming
    Replies: 3
    Last Post: 14th June 2012, 04:16
  4. How to implement a graphical curve drawing/editing tool
    By hakiim35 in forum Qt Programming
    Replies: 3
    Last Post: 21st December 2010, 21:40
  5. Grouping of Tool buttons in Tool bar
    By febil in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2009, 11:51

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.