Paint. editor

  • I want to make a pixel editor, but i don't know how start, any tips?

    Thanks in advance.

  • Focus around QPainter and QPixmap. A brush can be represented by a monochrome 8 bit pixmap you can colorize in the desired color, then using QPainter you can imprint the brush pixmap onto another pixmap that represents your canvas.

    Keep in mind that QBrush won't provide the needed behavior.

    If this is your brush stencil:

    using QBrush to fill a stroke will produce this:

    it will fill the stroke in a patterned style instead of what an actual stroke with the stencil should look like:

    Typically, you'd want to store 2 coordinates while drawing, the previous and current position of the cursor. Then you create a QLine between the two QPoints and draw the brush pixmap along that line based on how much your brush spacing is. This is the approach needed to solve the issue, presented by Qt's slow input event polling, which would create arbitrary single points along the path of drawing instead of a consistent line.

    Of course if you want only single pixel the task will be much easier. Bud going for the "brush" approach will allow you to draw with any kind of brush, not only pixel. You can also create brushes that automatically rotate to follow the direction of drawing, brush dynamics in regard to size, opacity, color, noise and so on.

    On how to colorize your brush, I already show a well commented step by step example "here":

    There is also a sketch example shipping with Qt, but it is very limited in providing the ability to use different brush stencils.

  • Thank you!!! Thank you!!! Thank you!!!! utcenter ;) This and your other posts were exactly the information I have been looking for, Please post more on the subject of this topic when you can. It would be much appreciated.

    Thank you soooo much!!!!

Log in to reply