How to make brush tool in Graphics View Framework?
-
wrote on 8 Jan 2020, 22:17 last edited by
Hello,
I work on Graphics Editor. I've added brush tool to my application, but as you can see, it looks awfull. Now, brush tool is based on QGraphicsLineItem placed point by point. How to make it works more like in other editors eg. Gimp? I tried to use QGraphicsEllipseItem, but there was "white spaces" between circles –it wasn't continous line. I create those items in scene inside mouseMoveEvent method -
You can try to set a pen on the
QGraphicsLineItem
and set its cap style to Qt::RoundCap.It sounds though as this will result in a lot of small items. The performance of this solution is not gonna be great if you add a lot of lines like that. You can take a look at QGraphicsPathItem and just add new control points to the path.
Still, do you even need to keep the separate items? Maybe you could just rasterize them.
-
wrote on 9 Jan 2020, 20:39 last edited by
@Chris-Kawa said in How to make brush tool in Graphics View Framework?:
Still, do you even need to keep the separate items? Maybe you could just rasterize them.
Well, how to rasterize items? :)
-
@Chris-Kawa said in How to make brush tool in Graphics View Framework?:
Still, do you even need to keep the separate items? Maybe you could just rasterize them.
Well, how to rasterize items? :)
@clostridium_difficile said:
Well, how to rasterize items? :)
Just paint them on a
QPixmap
withQPainter
. -
Hello,
I work on Graphics Editor. I've added brush tool to my application, but as you can see, it looks awfull. Now, brush tool is based on QGraphicsLineItem placed point by point. How to make it works more like in other editors eg. Gimp? I tried to use QGraphicsEllipseItem, but there was "white spaces" between circles –it wasn't continous line. I create those items in scene inside mouseMoveEvent methodwrote on 9 Jan 2020, 23:56 last edited by@clostridium_difficile Why is it that you are so dedicated to using GraphicsView to make a paint app? It seems like a really odd design goal, because that's not what it's meant for. Paint applications like Photoshop, GIMP or Krita don't use similar interfaces where they retain all brush strokes as live objects. And even "vector paint" systems like Nuke do their own implementation that is quite different. You really are trying to fit a square peg in a round hole.
A typical paint app just draws the user's input strokes into a bitmap image and accumulates the result. Here's a writeup of a paper on rendering brush strokes that you might find interesting if you decide to do it yourself -- http://apoorvaj.io/efficient-rendering-of-linear-brush-strokes.html You could also consider just using a QPainter on a QImage, and using painter paths or drawing many circles along a path, etc. If you do retain the vector paint approach, you definitely only want to retain an object per-stroke, and not many objects for each stroke like having a zillion line objects that you need to retain in memory and individually draw with each refresh.
1/5