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. "Not so basic" drawing application
QtWS25 Last Chance

"Not so basic" drawing application

Scheduled Pinned Locked Moved General and Desktop
24 Posts 4 Posters 13.3k Views
  • 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #7

    Why don't you change the logic of the painting instead? It looks like now you are paiting a point whereever you find the mouse, but why don't you draw a line between where your mouse last was and your mouse is now instead?

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #8

      [quote author="Andre" date="1330617520"]Why don't you change the logic of the painting instead? It looks like now you are paiting a point whereever you find the mouse, but why don't you draw a line between where your mouse last was and your mouse is now instead?[/quote]

      Because this is not the way a drawing application works. If I wanted to just create lines, I would have done exactly that. I need drawing logic that can draw with different stencils / brushes much like photoshop, and in fact the user needs to be able to create his own custom brushes. The location of brushes must be randomized, the size - dynamic, brushes must rotate and all that stuff, scatter and so on, this cannot be achieved by drawing lines between locations on the screen.

      There is nothing wrong with the logic of the painting as it is, I tested it with very big stencils and performance is great, the bottleneck is the update rate of the event loop.

      How can I control it, so I can make it faster while drawing?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #9

        You can not control it, that's the point. Perhaps you should not use lines as such, but you should probably use the last and the current position of the mouse to do your rendering. You simply cannot rely on getting a mouse move event for every pixel on your screen you pass over.

        You could perhaps use the moving speed in some way, using not only the last and the previous position, but also the time between these events. That would allow you to gauge if the user is very quick, or your system is just a bit slow. That might result in a different stroke in terms of your painting.

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #10

          I see I will have to interpolate to get the in-between polling locations...

          I noticed photoshop has an option on the brush called "spacing" and with it disabled, it behaves EXACTLY the same way as my test application. In fact the spacing in photoshop is even larger, probably because the application is heavy on the cpu.

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #11

            So, my next logical question is if there is a way to "draw a line" but not with a pen but by dragging a pixmap or a QBrush? I was just looking through the doc and all the methods for drawing lines involve QPen or a stroke which doesn't seem to be able to consist of an image.

            If not, I will have to do go back to the tedious interpolation...

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #12

              Well, a QPen consists of a QBrush consists of a QPixmap.

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #13

                Yes, but it works nowhere near the way I need it to. Here is what it looks like:
                !http://i42.tinypic.com/xd9nup.png(wrong)!

                I don't need to fill the "volume" of the line with a pattern of the QBrush, I need to paint by dragging the brush for every pixel of the line. Notice the subtle difference? :)
                !http://i44.tinypic.com/35a1w5t.png(right)!

                1 Reply Last reply
                0
                • EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by
                  #14

                  Have you looked at the scribble example?

                  Qt Certified Specialist
                  www.edalsolutions.be

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #15

                    Yes, it only uses an outline pen, it will work for the image posted above but it wont work for something like this:

                    !http://i41.tinypic.com/34hcewg.png(pixmap)!

                    The whole point is to not be restricted to a plain line (like scribble example is) but be able to paint by dragging the stencil you want to draw with.

                    Here is what scribble draws with:

                    @painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
                    painter.drawLine(lastPoint, endPoint);@

                    And in fact, my very first post states that I failed to find what I need in the examples ;)

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #16

                      Looks like this code will do exactly what you just showed above in your second example, and that you showed as an example of what you wanted...

                      1 Reply Last reply
                      0
                      • ? This user is from outside of this forum
                        ? This user is from outside of this forum
                        Guest
                        wrote on last edited by
                        #17

                        There seems to be a form of miscommunication here, so lets go through everything step by step.

                        1 - this is my "brush" or stencil:
                        !http://i41.tinypic.com/34dr5nt.png(stencil)!

                        2 - this is what happens when I put the brush inside a QPixmap, which I put inside a QBrush, which I put inside a QPen
                        !http://i41.tinypic.com/21mde8j.png(wrong)!

                        The line is simply filled with a tiled pattern of the stencil
                        and the code for all of this:
                        @ QPainter painter(this);
                        QPixmap brush("c:/brush.png");
                        QBrush myBrush(Qt::red, brush);
                        QPen myPen;
                        myPen.setWidth(50);
                        myPen.setBrush(myBrush);
                        painter.setPen(myPen);
                        painter.drawLine(10, 10, 200, 50);@

                        note that I use the same method as in the scribble example, BUT this method only works for either solid or dashed lines, not for the stencil

                        3 - here is what dragging the stencil to draw should actually result it:
                        !http://i39.tinypic.com/2642m2e.png(right)!

                        drawLine can only draw strokes, not fills, strokes can only be solid or dashed but not pixmap, when a brush is set to a pen it tiles to fill the line, does not actually drag to draw it.

                        From DOC:

                        bq. The brush is used to fill strokes generated with the pen.

                        I don't need to fill the stroke with the brush, I need to DRAW it with the brush.
                        Is there a method to achieve the desired result?

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on last edited by
                          #18

                          Wouldn't it as simple as interpolating between the two points, and simply blitting the stencil at every point in between? Just guessing here...

                          1 Reply Last reply
                          0
                          • ? This user is from outside of this forum
                            ? This user is from outside of this forum
                            Guest
                            wrote on last edited by
                            #19

                            That was what I suggested many posts back as an alternative, in case there is no QPainter method to do that. It's just that you guys kept on insisting there is ;)

                            1 Reply Last reply
                            0
                            • J Offline
                              J Offline
                              Jake007
                              wrote on last edited by
                              #20

                              Or you can use GIMP ;) .

                              Please mark thread as solved if you found the solution.


                              Code is poetry

                              1 Reply Last reply
                              0
                              • ? This user is from outside of this forum
                                ? This user is from outside of this forum
                                Guest
                                wrote on last edited by
                                #21

                                ^^ And how exactly is your post helpful? From the many images I posted you should have concluded I already have a commercial image editor. And how exactly will GIMP help me to draw lines with stencils in my application? And thanks for your suggestion but I have plenty more questions on this topic, but those will have to wait till tomorrow. Geez... hunt rank much?

                                Anyway, I was able to do it with interpolation, the following is an actual screenshot, but it is a primitive, quick and dirty way to interpolate, and it shows - the lines are quite jagged, nowhere nearly as smooth as those in the images above, which I made in photoshop, will have to do some optimization tomorrow.
                                !http://i39.tinypic.com/2ntabgm.png(final)!

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  andre
                                  wrote on last edited by
                                  #22

                                  Perhaps you can study how Krita works? From wat I read in the past, it is quite advanced in terms of brush handling.

                                  1 Reply Last reply
                                  0
                                  • ? This user is from outside of this forum
                                    ? This user is from outside of this forum
                                    Guest
                                    wrote on last edited by
                                    #23

                                    Reinventing the wheel is usually a bad idea, but looking at the source code for Krita all I find is method calls within method calls within method calls, never really reaching the actual drawing logic. The project is so vast it will probably take me less time to reinvent the wheel in that particular case...

                                    Perhaps if someone here is familiar with the project can give me a few pointers on where to look...

                                    As for reinventing the wheel, I do realize I am stepping out of Qt land into generic algorithms so I will take it elsewhere.

                                    1 Reply Last reply
                                    0
                                    • ? This user is from outside of this forum
                                      ? This user is from outside of this forum
                                      Guest
                                      wrote on last edited by
                                      #24

                                      BTW, here is my interpolation logic, it is fairly primitive, but I ain't no programmer yet, and I do realize Qt might have a better API for this, so any recommendations are welcome!

                                      @void Widget::drawLine()
                                      {
                                      QPointF point, drawPoint;
                                      point = newPos - lastPos;
                                      int length = point.manhattanLength();
                                      double xInc, yInc;

                                      xInc = point.x() / length;
                                      yInc = point.y() / length;
                                      
                                      drawPoint = lastPos;
                                      
                                      for (int x=0; x < length; ++x) {
                                          drawPoint.setX(drawPoint.x()+xInc);
                                          drawPoint.setY(drawPoint.y()+yInc);
                                          drawToCanvas(drawPoint);
                                      }
                                      

                                      }@

                                      Edit: One optimization that comes to mind looking at the code now is use the rx and ry methods of QPoint that return references to use the += on and save the extra function call...

                                      1 Reply Last reply
                                      0

                                      • Login

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