Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make brush tool in Graphics View Framework?
Forum Updated to NodeBB v4.3 + New Features

How to make brush tool in Graphics View Framework?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 443 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    clostridium_difficile
    wrote on 8 Jan 2020, 22:17 last edited by
    #1

    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 brushTool.png

    W 1 Reply Last reply 9 Jan 2020, 23:56
    0
    • C Online
      C Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on 9 Jan 2020, 15:12 last edited by
      #2

      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.

      1 Reply Last reply
      1
      • C Offline
        C Offline
        clostridium_difficile
        wrote on 9 Jan 2020, 20:39 last edited by
        #3

        @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? :)

        C 1 Reply Last reply 9 Jan 2020, 22:59
        0
        • C clostridium_difficile
          9 Jan 2020, 20:39

          @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? :)

          C Online
          C Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on 9 Jan 2020, 22:59 last edited by
          #4

          @clostridium_difficile said:

          Well, how to rasterize items? :)

          Just paint them on a QPixmap with QPainter.

          1 Reply Last reply
          0
          • C clostridium_difficile
            8 Jan 2020, 22:17

            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 brushTool.png

            W Offline
            W Offline
            wrosecrans
            wrote on 9 Jan 2020, 23:56 last edited by
            #5

            @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 Reply Last reply
            3

            1/5

            8 Jan 2020, 22:17

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved