How to use QPainter: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
(Added LangSwitch)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
==Introduction==
{{LangSwitch}}
[[Category:HowTo]]
[[Category:Snippets]]
[[Category:Tutorial]]
[[Category:Learning]]


QPainter provides standard functions to draw points, lines, ellipses, arcs, B’ezier curves, and other primitives. More complex painting operations include support for polygons and vector paths, allowing detailed drawings to be prepared in advance and drawn using a single function call. Text can also be painted directly with a painter or incorporated in a path for later use.
__NOEDITSECTION__
<div style="float:left;padding:14px;">__TOC__</div>


Qt’s painting system also provides a number of features to improve overall rendering quality, including alpha blending, Porter-Duff composition modes, anti-aliasing, and linear, radial and conical gradient fills.
== Introduction ==


==First steps==
{{DocLink|QPainter}} provides standard functions to draw points, lines, ellipses, arcs, Bézier curves, and other primitives. More complex painting operations include support for polygons and vector paths, allowing detailed drawings to be prepared in advance and drawn using a single function call. Text can also be painted directly with a painter or incorporated in a path for later use.


'''<span class="caps">IMPORTANT</span>!''' QPainter can paint on QWidget only in <code>paintEvent(QPaintEvent *)</code>. Sample code:<br />
Qt's painting system also provides a number of features to improve overall rendering quality, including alpha blending, [http://de.wikipedia.org/wiki/Porter-Duff_Composition Porter-Duff] composition modes, anti-aliasing, and linear, radial and conical gradient fills.


This snippet will draw black line on widget. Now we know how to create QPainter object and write on widget. But this isn’t only one of supporting context’s. he can draw on QPrinter, QPicture, QPixmap, QBitmap, QImage, QGLPixelBuffer.
== First steps ==


==Pen and brush==
'''IMPORTANT!''' QPainter can paint on QWidget only in <tt>paintEvent(QPaintEvent*)</tt>.


Pens and brushes are fundamental tools for graphic programming with Qt. Without them, you can’t do anything. So, let’s talk about them.
Sample code:


====Pen====
<code>
void paintEvent(QPaintEvent*)
{
QPainter painter(this);
QLineF line(10.0, 80.0, 90.0, 20.0);
painter.drawLine(line);
}
</code>


Basic usage of pen is drawing circuit lines of shape.
This snippet will draw black line on the widget. Now we know how to create QPainter object and draw on widgets. But this isn't only supported drawing context. It is also possible to draw on {{DocLink|QPrinter}}, {{DocLink|QPicture}}, {{DocLink|QPixmap}}, {{DocLink|QBitmap}}, {{DocLink|QImage}}, {{DocLink|QGLPixelBuffer}}.


===Categories:===
== QPen and QBrush ==


* [[:Category:Developing with Qt|Developing_with_Qt]]
Pens and brushes are fundamental tools for graphic programming with Qt. Without them, you can't do anything. Further information is available at {{DocLink|QPen}} and {{DocLink|QBrush}}.

Latest revision as of 19:41, 28 June 2015

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh


Introduction

QPainter provides standard functions to draw points, lines, ellipses, arcs, Bézier curves, and other primitives. More complex painting operations include support for polygons and vector paths, allowing detailed drawings to be prepared in advance and drawn using a single function call. Text can also be painted directly with a painter or incorporated in a path for later use.

Qt's painting system also provides a number of features to improve overall rendering quality, including alpha blending, Porter-Duff composition modes, anti-aliasing, and linear, radial and conical gradient fills.

First steps

IMPORTANT! QPainter can paint on QWidget only in paintEvent(QPaintEvent*).

Sample code:

void paintEvent(QPaintEvent*)
{
 QPainter painter(this);
 QLineF line(10.0, 80.0, 90.0, 20.0);
 painter.drawLine(line);
}

This snippet will draw black line on the widget. Now we know how to create QPainter object and draw on widgets. But this isn't only supported drawing context. It is also possible to draw on QPrinter, QPicture, QPixmap, QBitmap, QImage, QGLPixelBuffer.

QPen and QBrush

Pens and brushes are fundamental tools for graphic programming with Qt. Without them, you can't do anything. Further information is available at QPen and QBrush.