This is a typedef for a pointer to a function with the following
signature:
- \snippet doc/src/snippets/code/src_gui_accessible_qaccessible.cpp 1
+ \snippet code/src_gui_accessible_qaccessible.cpp 1
The function receives a QString and a QObject pointer, where the
QString is the key identifying the interface. The QObject is used
--- /dev/null
+include(../../../doc/global/qt-cpp-ignore.qdocconf)
+
+project = QtGui
+description = Qt GUI Reference Documentation
+url = http://qt-project.org/doc/qt-5.0/qtgui
+version = 5.0.0
+
+sourceencoding = UTF-8
+outputencoding = UTF-8
+naturallanguage = en_US
+qhp.projects = QtGui
+
+qhp.QtGui.file = qtgui.qhp
+qhp.QtGui.namespace = org.qt-project.qtgui.500
+qhp.QtGui.virtualFolder = qdoc
+qhp.QtGui.indexTitle = Qt GUI Reference Documentation
+qhp.QtGui.indexRoot =
+
+qhp.QtGui.filterAttributes = qtgui 5.0.0 qtrefdoc
+qhp.QtGui.customFilters.Qt.name = Qtgui 5.0.0
+qhp.QtGui.customFilters.Qt.filterAttributes = qtgui 5.0.0
+qhp.QtGui.subprojects = classes overviews examples
+qhp.QtGui.subprojects.classes.title = Classes
+qhp.QtGui.subprojects.classes.indexTitle = Qt GUI's Classes
+qhp.QtGui.subprojects.classes.selectors = class fake:headerfile
+qhp.QtGui.subprojects.classes.sortPages = true
+qhp.QtGui.subprojects.overviews.title = Overviews
+qhp.QtGui.subprojects.overviews.indexTitle = All Overviews and HOWTOs
+qhp.QtGui.subprojects.overviews.selectors = fake:page,group,module
+qhp.QtGui.subprojects.examples.title = Qt GUI Examples
+qhp.QtGui.subprojects.examples.indexTitle = Qt GUI Examples
+qhp.QtGui.subprojects.examples.selectors = fake:example
+
+dita.metadata.default.author = Qt Project
+dita.metadata.default.permissions = all
+dita.metadata.default.publisher = Qt Project
+dita.metadata.default.copyryear = 2012
+dita.metadata.default.copyrholder = Nokia
+dita.metadata.default.audience = programmer
+
+sources.fileextensions = "*.c++ *.cc *.cpp *.cxx *.mm *.qml *.qdoc"
+headers.fileextensions = "*.ch *.h *.h++ *.hh *.hpp *.hxx"
+
+examples.fileextensions = "*.cpp *.h *.js *.xq *.svg *.xml *.ui *.qhp *.qhcp *.qml *.css"
+examples.imageextensions = "*.png"
+
+outputdir = ../../../doc/qtgui
+tagfile = ../../../doc/qtgui/qtgui.tags
+
+HTML.generatemacrefs = "true"
+HTML.nobreadcrumbs = "true"
+
+HTML.templatedir = .
+
+HTML.stylesheets = ../../../doc/global/style/offline.css
+
+HTML.headerstyles = \
+ " <link rel=\"stylesheet\" type=\"text/css\" href=\"style/offline.css\" />\n"
+
+HTML.endheader = \
+ "</head>\n" \
+
+defines = Q_QDOC \
+ QT_.*_SUPPORT \
+ QT_.*_LIB \
+ QT_COMPAT \
+ QT_KEYPAD_NAVIGATION \
+ QT_NO_EGL \
+ Q_WS_.* \
+ Q_OS_.* \
+ Q_BYTE_ORDER \
+ QT_DEPRECATED \
+ QT_DEPRECATED_* \
+ Q_NO_USING_KEYWORD \
+ __cplusplus \
+ Q_COMPILER_INITIALIZER_LISTS
+
+versionsym = QT_VERSION_STR
+
+codeindent = 1
+
+depends += qtcore
+
+headerdirs += ..
+
+sourcedirs += ..
+
+exampledirs += ../../../examples \
+ ../ \
+ snippets
+
+imagedirs += images
To include the definitions of both modules' classes, use the
following directive:
- \snippet doc/src/snippets/code/doc_src_qtgui.pro 0
+ \snippet code/doc_src_qtgui.pro 0
*/
\row
\li \inlineimage qimage-32bit_scaled.png
\li
- \snippet doc/src/snippets/code/src_gui_image_qimage.cpp 0
+ \snippet code/src_gui_image_qimage.cpp 0
\endtable
In case of a 8-bit and monchrome images, the pixel value is only
\row
\li \inlineimage qimage-8bit_scaled.png
\li
- \snippet doc/src/snippets/code/src_gui_image_qimage.cpp 1
+ \snippet code/src_gui_image_qimage.cpp 1
\endtable
QImage also provide the scanLine() function which returns a
Note that it's possible to squeeze the XPM variable a little bit
by using an unusual declaration:
- \snippet doc/src/snippets/code/src_gui_image_qimage.cpp 2
+ \snippet code/src_gui_image_qimage.cpp 2
The extra \c const makes the entire definition read-only, which is
slightly more efficient (e.g., when the code is in a shared
This can, for example, be used to save an image directly into a
QByteArray:
- \snippet doc/src/snippets/image/image.cpp 0
+ \snippet image/image.cpp 0
*/
bool QImage::save(QIODevice* device, const char* format, int quality) const
if a specific image or format supports embedding text
by using QImageWriter::supportsOption(). We give an example:
- \snippet doc/src/snippets/image/supportedformat.cpp 0
+ \snippet image/supportedformat.cpp 0
You can use QImageWriter::supportedImageFormats() to find out
which image formats are available to you.
Sets the format QImageReader will use when reading images, to \a
format. \a format is a case insensitive text string. Example:
- \snippet doc/src/snippets/code/src_gui_image_qimagereader.cpp 0
+ \snippet code/src_gui_image_qimagereader.cpp 0
You can call supportedImageFormats() for the full list of formats
QImageReader supports.
You can call this function after assigning a device to the
reader to determine the format of the device. For example:
- \snippet doc/src/snippets/code/src_gui_image_qimagereader.cpp 1
+ \snippet code/src_gui_image_qimagereader.cpp 1
If the reader cannot read any image from the device (e.g., there is no
image there, or the image has already been read), or if the format is
which always constructs a new image; especially when reading several
images with the same format and size.
- \snippet doc/src/snippets/code/src_gui_image_qimagereader.cpp 2
+ \snippet code/src_gui_image_qimagereader.cpp 2
For image formats that support animation, calling read() repeatedly will
return the next frame. When all frames have been read, a null image will
(see text()), and the BMP format allows you to determine the image's size
without loading the whole image into memory (see size()).
- \snippet doc/src/snippets/code/src_gui_image_qimagereader.cpp 3
+ \snippet code/src_gui_image_qimagereader.cpp 3
\sa QImageWriter::supportsOption()
*/
Sets the format QImageWriter will use when writing images, to \a
format. \a format is a case insensitive text string. Example:
- \snippet doc/src/snippets/code/src_gui_image_qimagewriter.cpp 0
+ \snippet code/src_gui_image_qimagewriter.cpp 0
You can call supportedImageFormats() for the full list of formats
QImageWriter supports.
\a text. This is useful for storing copyright information
or other information about the image. Example:
- \snippet doc/src/snippets/code/src_gui_image_qimagewriter.cpp 1
+ \snippet code/src_gui_image_qimagewriter.cpp 1
If you want to store a single block of data
(e.g., a comment), you can pass an empty key, or use
example, the PNG format allows you to embed text into the image's metadata
(see text()).
- \snippet doc/src/snippets/code/src_gui_image_qimagewriter.cpp 2
+ \snippet code/src_gui_image_qimagewriter.cpp 2
Options can be tested after the writer has been associated with a format.
To display the movie in your application, you can pass your QMovie object
to QLabel::setMovie(). Example:
- \snippet doc/src/snippets/code/src_gui_image_qmovie.cpp 0
+ \snippet code/src_gui_image_qmovie.cpp 0
Whenever a new frame is available in the movie, QMovie will emit
updated(). If the size of the frame changes, resized() is emitted. You can
The default speed is 100%.
Example:
- \snippet doc/src/snippets/code/src_gui_image_qmovie.cpp 1
+ \snippet code/src_gui_image_qmovie.cpp 1
*/
void QMovie::setSpeed(int percentSpeed)
{
depending on the window system.
Example of how to record a picture:
- \snippet doc/src/snippets/picture/picture.cpp 0
+ \snippet picture/picture.cpp 0
Note that the list of painter commands is reset on each call to
the QPainter::begin() function.
Example of how to replay a picture:
- \snippet doc/src/snippets/picture/picture.cpp 1
+ \snippet picture/picture.cpp 1
Pictures can also be drawn using play(). Some basic data about a
picture is available, for example, size(), isNull() and
Note that if you want to iterate over the list, you should iterate
over a copy, e.g.
- \snippet doc/src/snippets/picture/picture.cpp 2
+ \snippet picture/picture.cpp 2
\sa outputFormatList() inputFormats() QPictureIO
*/
Note that if you want to iterate over the list, you should iterate
over a copy, e.g.
- \snippet doc/src/snippets/picture/picture.cpp 3
+ \snippet picture/picture.cpp 3
\sa inputFormatList() outputFormats() QPictureIO
*/
both are null, the QPictureIO object is valid but useless.
Example:
- \snippet doc/src/snippets/picture/picture.cpp 6
+ \snippet picture/picture.cpp 6
\codeline
- \snippet doc/src/snippets/picture/picture.cpp 7
+ \snippet picture/picture.cpp 7
\codeline
- \snippet doc/src/snippets/picture/picture.cpp 8
+ \snippet picture/picture.cpp 8
Before the regular expression test, all the 0 bytes in the file header are
converted to 1 bytes. This is done because when Qt was ASCII-based, QRegExp
Example:
- \snippet doc/src/snippets/picture/picture.cpp 4
+ \snippet picture/picture.cpp 4
\sa setIODevice() setFileName() setFormat() write() QPixmap::load()
*/
The picture will be written using the specified picture format.
Example:
- \snippet doc/src/snippets/picture/picture.cpp 5
+ \snippet picture/picture.cpp 5
\sa setIODevice() setFileName() setFormat() read() QPixmap::save()
*/
Note that it's possible to squeeze the XPM variable a little bit
by using an unusual declaration:
- \snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 0
+ \snippet code/src_gui_image_qpixmap.cpp 0
The extra \c const makes the entire definition read-only, which is
slightly more efficient (for example, when the code is in a shared
region is left unchanged. You can optionally pass a pointer to an empty
QRegion to get the region that is \a exposed by the scroll operation.
- \snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 2
+ \snippet code/src_gui_image_qpixmap.cpp 2
You cannot scroll while there is an active painter on the pixmap.
The mask may not be perfect but it should be reasonable, so you
can do things such as the following:
- \snippet doc/src/snippets/code/src_gui_image_qpixmap.cpp 1
+ \snippet code/src_gui_image_qpixmap.cpp 1
This function is slow because it involves converting to/from a
QImage, and non-trivial computations.
specified image file \a format and \a quality factor. This can be
used, for example, to save a pixmap directly into a QByteArray:
- \snippet doc/src/snippets/image/image.cpp 1
+ \snippet image/image.cpp 1
*/
bool QPixmap::save(QIODevice* device, const char* format, int quality) const
bool find(const QString&, QPixmap*) instead.
Example:
- \snippet doc/src/snippets/code/src_gui_image_qpixmapcache.cpp 0
+ \snippet code/src_gui_image_qpixmapcache.cpp 0
*/
QPixmap *QPixmapCache::find(const QString &key)
\since 4.6
Example:
- \snippet doc/src/snippets/code/src_gui_image_qpixmapcache.cpp 1
+ \snippet code/src_gui_image_qpixmapcache.cpp 1
*/
bool QPixmapCache::find(const QString &key, QPixmap* pixmap)
as QApplication::clipboard().
Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qclipboard.cpp 0
+ \snippet code/src_gui_kernel_qclipboard.cpp 0
QClipboard features some convenience functions to access common
data types: setText() allows the exchange of Unicode text and
A typical example of the use of these functions follows:
- \snippet doc/src/snippets/droparea.cpp 0
+ \snippet droparea.cpp 0
\section1 Notes for X11 Users
This is shorthand for:
- \snippet doc/src/snippets/code/src_gui_kernel_qclipboard.cpp 1
+ \snippet code/src_gui_kernel_qclipboard.cpp 1
\sa image(), setPixmap() setMimeData()
*/
QMimeData object. This is specified with the setMimeData() function in the
following way:
- \snippet doc/src/snippets/dragging/mainwindow.cpp 1
+ \snippet dragging/mainwindow.cpp 1
Note that setMimeData() assigns ownership of the QMimeData object to the
QDrag object. The QDrag must be constructed on the heap with a parent QObject
that the cursor's hot spot points to the center of its bottom
edge:
- \snippet doc/src/snippets/separations/finalwidget.cpp 2
+ \snippet separations/finalwidget.cpp 2
\note On X11, the pixmap may not be able to keep up with the mouse
movements if the hot spot causes the pixmap to be displayed
Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qevent.cpp 0
+ \snippet code/src_gui_kernel_qevent.cpp 0
*/
/*!
Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qevent.cpp 0
+ \snippet code/src_gui_kernel_qevent.cpp 0
*/
/*!
\table 100%
\row
\li
- \snippet doc/src/snippets/qstatustipevent/main.cpp 1
+ \snippet qstatustipevent/main.cpp 1
\dots
- \snippet doc/src/snippets/qstatustipevent/main.cpp 3
+ \snippet qstatustipevent/main.cpp 3
\li
\image qstatustipevent-widget.png Widget with status tip.
\endtable
\table 100%
\row
\li
- \snippet doc/src/snippets/qstatustipevent/main.cpp 0
- \snippet doc/src/snippets/qstatustipevent/main.cpp 2
+ \snippet qstatustipevent/main.cpp 0
+ \snippet qstatustipevent/main.cpp 2
\dots
- \snippet doc/src/snippets/qstatustipevent/main.cpp 3
+ \snippet qstatustipevent/main.cpp 3
\li
\image qstatustipevent-action.png Action with status tip.
\endtable
restoreOverrideCursor(), otherwise the stack will never be emptied.
Example:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication_x11.cpp 0
+ \snippet code/src_gui_kernel_qapplication_x11.cpp 0
\sa overrideCursor(), restoreOverrideCursor(), changeOverrideCursor(),
QWidget::setCursor()
This function must be called before creating the QGuiApplication object, like
this:
- \snippet doc/src/snippets/code/src_gui_kernel_qapplication.cpp 6
+ \snippet code/src_gui_kernel_qapplication.cpp 6
\sa desktopSettingsAware()
*/
printing a document, and can be specified in any of the following
ways:
- \snippet doc/src/snippets/code/src_gui_kernel_qkeysequence.cpp 0
+ \snippet code/src_gui_kernel_qkeysequence.cpp 0
Note that, for letters, the case used in the specification string
does not matter. In the above examples, the user does not need to
For example, the key sequence, \key{Ctrl X} followed by \key{Ctrl C}, can
be specified using either of the following ways:
- \snippet doc/src/snippets/code/src_gui_kernel_qkeysequence.cpp 1
+ \snippet code/src_gui_kernel_qkeysequence.cpp 1
\warning A QApplication instance must have been constructed before a
QKeySequence is created; otherwise, your application may crash.
\endlink(), so that shortcut keys can be replaced in
translations:
- \snippet doc/src/snippets/code/src_gui_kernel_qkeysequence.cpp 2
+ \snippet code/src_gui_kernel_qkeysequence.cpp 2
Note the "File|Open" translator comment. It is by no means
necessary, but it provides some context for the human translator.
and the QTextDocument::setDefaultStyleSheet() function to alter
the appearance of links. For example:
- \snippet doc/src/snippets/textdocument-css/main.cpp 0
+ \snippet textdocument-css/main.cpp 0
\value NoRole No role; this special role is often used to indicate that a
role has not been assigned.
/*! \internal
Clears \a seq to an empty QKeySequence.
Same as doing (the slower)
- \snippet doc/src/snippets/code/src_gui_kernel_qshortcutmap.cpp 0
+ \snippet code/src_gui_kernel_qshortcutmap.cpp 0
*/
void QShortcutMap::clearSequence(QVector<QKeySequence> &ksl)
{
program is activated in the current QOpenGLContext by calling
QOpenGLShaderProgram::bind():
- \snippet doc/src/snippets/code/src_gui_qopenglshaderprogram.cpp 0
+ \snippet code/src_gui_qopenglshaderprogram.cpp 0
\section1 Writing portable shaders
\section1 Simple shader example
- \snippet doc/src/snippets/code/src_gui_qopenglshaderprogram.cpp 1
+ \snippet code/src_gui_qopenglshaderprogram.cpp 1
With the above shader program active, we can draw a green triangle
as follows:
- \snippet doc/src/snippets/code/src_gui_qopenglshaderprogram.cpp 2
+ \snippet code/src_gui_qopenglshaderprogram.cpp 2
\section1 Binary shaders and programs
gradients: QLinearGradient, QConicalGradient, and QRadialGradient
- all of which inherit QGradient.
- \snippet doc/src/snippets/brush/gradientcreationsnippet.cpp 0
+ \snippet brush/gradientcreationsnippet.cpp 0
The texture() defines the pixmap used when the current style is
Qt::TexturePattern. You can create a brush with a texture by
QPainter's \l {QPen}{pen} combined with Qt::PenStyle and
Qt::GlobalColor:
- \snippet doc/src/snippets/code/src_gui_painting_qbrush.cpp 0
+ \snippet code/src_gui_painting_qbrush.cpp 0
Note that, by default, QPainter renders the outline (using the
currently set pen) when drawing shapes. Use \l {Qt::NoPen}{\c
A diagonal linear gradient from black at (100, 100) to white at
(200, 200) could be specified like this:
- \snippet doc/src/snippets/brush/brush.cpp 0
+ \snippet brush/brush.cpp 0
A gradient can have an arbitrary number of stop points. The
following would create a radial gradient starting with
red in the center, blue and then green on the edges:
- \snippet doc/src/snippets/brush/brush.cpp 1
+ \snippet brush/brush.cpp 1
It is possible to repeat or reflect the gradient outside its area
by specifiying the \l {QGradient::Spread}{spread method} using the
represents a fully transparent color, while 255 represents a fully
opaque color. For example:
- \snippet doc/src/snippets/code/src_gui_painting_qcolor.cpp 0
+ \snippet code/src_gui_painting_qcolor.cpp 0
The code above produces the following output:
\row
\li \inlineimage qmatrix-simpletransformation.png
\li
- \snippet doc/src/snippets/matrix/matrix.cpp 0
+ \snippet matrix/matrix.cpp 0
\endtable
Although these functions are very convenient, it can be more
\row
\li \inlineimage qmatrix-combinedtransformation.png
\li
- \snippet doc/src/snippets/matrix/matrix.cpp 1
+ \snippet matrix/matrix.cpp 1
\endtable
\section1 Basic Matrix Operations
QMatrix transforms a point in the plane to another point using the
following formulas:
- \snippet doc/src/snippets/code/src_gui_painting_qmatrix.cpp 0
+ \snippet code/src_gui_painting_qmatrix.cpp 0
The point \e (x, y) is the original point, and \e (x', y') is the
transformed point. \e (x', y') can be transformed back to \e (x,
\row
\li \inlineimage qmatrix-combinedtransformation.png
\li
- \snippet doc/src/snippets/matrix/matrix.cpp 2
+ \snippet matrix/matrix.cpp 2
\endtable
\sa QPainter, QTransform, {Coordinate System},
The coordinates are transformed using the following formulas:
- \snippet doc/src/snippets/code/src_gui_painting_qmatrix.cpp 1
+ \snippet code/src_gui_painting_qmatrix.cpp 1
The point (x, y) is the original point, and (x', y') is the
transformed point.
The rectangle's coordinates are transformed using the following
formulas:
- \snippet doc/src/snippets/code/src_gui_painting_qmatrix.cpp 2
+ \snippet code/src_gui_painting_qmatrix.cpp 2
If rotation or shearing has been specified, this function returns
the \e bounding rectangle. To retrieve the exact region the given
The rectangle's coordinates are transformed using the following
formulas:
- \snippet doc/src/snippets/code/src_gui_painting_qmatrix.cpp 3
+ \snippet code/src_gui_painting_qmatrix.cpp 3
Polygons and rectangles behave slightly differently when
transformed (due to integer rounding), so
painter. Then draw. Remember to destroy the QPainter object after
drawing. For example:
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 0
+ \snippet code/src_gui_painting_qpainter.cpp 0
The core functionality of QPainter is drawing, but the class also
provide several functions that allows you to customize QPainter's
automatically calls end().
Here's an example using begin() and end():
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 1
+ \snippet code/src_gui_painting_qpainter.cpp 1
The same example using this constructor:
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 2
+ \snippet code/src_gui_painting_qpainter.cpp 2
Since the constructor cannot provide feedback when the initialization
of the painter failed you should rather use begin() and end() to paint
The errors that can occur are serious problems, such as these:
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 3
+ \snippet code/src_gui_painting_qpainter.cpp 3
Note that most of the time, you can use one of the constructors
instead of begin(), and that end() is automatically done at
default state by endNativePainting(). Here is an example that shows
intermixing of painter commands and raw OpenGL commands:
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 21
+ \snippet code/src_gui_painting_qpainter.cpp 21
\sa endNativePainting()
*/
They operate on the painter's worldMatrix() and are implemented like this:
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 4
+ \snippet code/src_gui_painting_qpainter.cpp 4
Note that when using setWorldMatrix() function you should always have
\a combine be true when you are drawing into a QPicture. Otherwise
\row
\li \inlineimage qpainter-path.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 5
+ \snippet code/src_gui_painting_qpainter.cpp 5
\endtable
\sa {painting/painterpaths}{the Painter Paths
\row
\li \inlineimage qpainter-line.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 6
+ \snippet code/src_gui_painting_qpainter.cpp 6
\endtable
\sa drawLines(), drawPolyline(), {Coordinate System}
\row
\li \inlineimage qpainter-rectangle.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 7
+ \snippet code/src_gui_painting_qpainter.cpp 7
\endtable
\sa drawRects(), drawPolygon(), {Coordinate System}
\row
\li \inlineimage qpainter-roundrect.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 8
+ \snippet code/src_gui_painting_qpainter.cpp 8
\endtable
\sa drawRect(), QPen
\row
\li \inlineimage qpainter-ellipse.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 9
+ \snippet code/src_gui_painting_qpainter.cpp 9
\endtable
\sa drawPie(), {Coordinate System}
\row
\li \inlineimage qpainter-arc.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 10
+ \snippet code/src_gui_painting_qpainter.cpp 10
\endtable
\sa drawPie(), drawChord(), {Coordinate System}
\row
\li \inlineimage qpainter-pie.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 11
+ \snippet code/src_gui_painting_qpainter.cpp 11
\endtable
\sa drawEllipse(), drawChord(), {Coordinate System}
\row
\li \inlineimage qpainter-chord.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 12
+ \snippet code/src_gui_painting_qpainter.cpp 12
\endtable
\sa drawArc(), drawPie(), {Coordinate System}
\table 100%
\row
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 13
+ \snippet code/src_gui_painting_qpainter.cpp 13
\endtable
\sa drawLines(), drawPolygon(), {Coordinate System}
\row
\li \inlineimage qpainter-polygon.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 14
+ \snippet code/src_gui_painting_qpainter.cpp 14
\endtable
The first point is implicitly connected to the last point, and the
\row
\li \inlineimage qpainter-polygon.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 15
+ \snippet code/src_gui_painting_qpainter.cpp 15
\endtable
The first point is implicitly connected to the last point, and the
\table 100%
\row
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 16
+ \snippet code/src_gui_painting_qpainter.cpp 16
\endtable
If \a pixmap is a QBitmap it is drawn with the bits that are "set"
\row
\li \inlineimage qpainter-text.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 17
+ \snippet code/src_gui_painting_qpainter.cpp 17
\endtable
The \a boundingRect (if not null) is set to the what the bounding rectangle
\table 100%
\row
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 18
+ \snippet code/src_gui_painting_qpainter.cpp 18
\endtable
\sa QPicture::play()
Erases the area inside the given \a rectangle. Equivalent to
calling
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 19
+ \snippet code/src_gui_painting_qpainter.cpp 19
\sa fillRect()
*/
\table 100%
\row
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainter.cpp 20
+ \snippet code/src_gui_painting_qpainter.cpp 20
\endtable
\sa drawPixmap()
\row
\li \inlineimage qpainterpath-construction.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 0
+ \snippet code/src_gui_painting_qpainterpath.cpp 0
\endtable
The painter path is initially empty when constructed. We first add
\row
\li \inlineimage qpainterpath-cubicto.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 1
+ \snippet code/src_gui_painting_qpainterpath.cpp 1
\endtable
\sa quadTo(), {QPainterPath#Composing a QPainterPath}{Composing
\row
\li \inlineimage qpainterpath-arcto.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 2
+ \snippet code/src_gui_painting_qpainterpath.cpp 2
\endtable
\sa arcMoveTo(), addEllipse(), QPainter::drawArc(), QPainter::drawPie(),
\row
\li \inlineimage qpainterpath-addrectangle.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 3
+ \snippet code/src_gui_painting_qpainterpath.cpp 3
\endtable
\sa addRegion(), lineTo(), {QPainterPath#Composing a
\row
\li \inlineimage qpainterpath-addpolygon.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 4
+ \snippet code/src_gui_painting_qpainterpath.cpp 4
\endtable
\sa lineTo(), {QPainterPath#Composing a QPainterPath}{Composing
\row
\li \inlineimage qpainterpath-addellipse.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 5
+ \snippet code/src_gui_painting_qpainterpath.cpp 5
\endtable
\sa arcTo(), QPainter::drawEllipse(), {QPainterPath#Composing a
\row
\li \inlineimage qpainterpath-addtext.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpainterpath.cpp 6
+ \snippet code/src_gui_painting_qpainterpath.cpp 6
\endtable
\sa QPainter::drawText(), {QPainterPath#Composing a
For example:
- \snippet doc/src/snippets/code/src_gui_painting_qpen.cpp 0
+ \snippet code/src_gui_painting_qpen.cpp 0
which is equivalent to
- \snippet doc/src/snippets/code/src_gui_painting_qpen.cpp 1
+ \snippet code/src_gui_painting_qpen.cpp 1
The default pen is a solid black brush with 0 width, square
cap style (Qt::SquareCap), and bevel join style (Qt::BevelJoin).
spaces. For example, the custom pattern shown above is created
using the following code:
- \snippet doc/src/snippets/code/src_gui_painting_qpen.cpp 2
+ \snippet code/src_gui_painting_qpen.cpp 2
Note that the dash pattern is specified in units of the pens
width, e.g. a dash of length 5 in width 10 is 50 pixels long.
\row
\li \inlineimage qpen-custom.png
\li
- \snippet doc/src/snippets/code/src_gui_painting_qpen.cpp 3
+ \snippet code/src_gui_painting_qpen.cpp 3
\endtable
The dash pattern is specified in units of the pens width; e.g. a
points to a QPolygon is to use QVector's streaming operator, as
illustrated below:
- \snippet doc/src/snippets/polygon/polygon.cpp 0
+ \snippet polygon/polygon.cpp 0
In addition to the functions provided by QVector, QPolygon
provides some point-specific functions.
The example code creates a polygon with two points (10, 20) and
(30, 40):
- \snippet doc/src/snippets/polygon/polygon.cpp 2
+ \snippet polygon/polygon.cpp 2
\sa setPoint() putPoints()
*/
The example code creates a polygon with two points (10, 20) and
(30, 40):
- \snippet doc/src/snippets/polygon/polygon.cpp 3
+ \snippet polygon/polygon.cpp 3
*/
void QPolygon::setPoints(int nPoints, int firstx, int firsty, ...)
The example code creates a polygon with three points (4,5), (6,7)
and (8,9), by expanding the polygon from 1 to 3 points:
- \snippet doc/src/snippets/polygon/polygon.cpp 4
+ \snippet polygon/polygon.cpp 4
The following code has the same result, but here the putPoints()
function overwrites rather than extends:
- \snippet doc/src/snippets/polygon/polygon.cpp 5
+ \snippet polygon/polygon.cpp 5
\sa setPoints()
*/
default) in \a fromPolygon into this polygon, starting at the
specified \a index. For example:
- \snippet doc/src/snippets/polygon/polygon.cpp 6
+ \snippet polygon/polygon.cpp 6
*/
void QPolygon::putPoints(int index, int nPoints, const QPolygon & from, int fromIndex)
to a QPolygonF is to use its streaming operator, as illustrated
below:
- \snippet doc/src/snippets/polygon/polygon.cpp 1
+ \snippet polygon/polygon.cpp 1
In addition to the functions provided by QVector, QPolygonF
provides the boundingRect() and translate() functions for geometry
rectangles.
Example of using complex regions:
- \snippet doc/src/snippets/code/src_gui_painting_qregion.cpp 0
+ \snippet code/src_gui_painting_qregion.cpp 0
\section1 Additional License Information
empty region is a region that contains no points.
Example:
- \snippet doc/src/snippets/code/src_gui_painting_qregion_unix.cpp 0
+ \snippet code/src_gui_painting_qregion_unix.cpp 0
*/
/*!
\row
\li \inlineimage qtransform-simpletransformation.png
\li
- \snippet doc/src/snippets/transform/main.cpp 0
+ \snippet transform/main.cpp 0
\endtable
Although these functions are very convenient, it can be more
\row
\li \inlineimage qtransform-combinedtransformation.png
\li
- \snippet doc/src/snippets/transform/main.cpp 1
+ \snippet transform/main.cpp 1
\endtable
\section1 Basic Matrix Operations
QTransform transforms a point in the plane to another point using the
following formulas:
- \snippet doc/src/snippets/code/src_gui_painting_qtransform.cpp 0
+ \snippet code/src_gui_painting_qtransform.cpp 0
The point \e (x, y) is the original point, and \e (x', y') is the
transformed point. \e (x', y') can be transformed back to \e (x,
\row
\li \inlineimage qtransform-combinedtransformation2.png
\li
- \snippet doc/src/snippets/transform/main.cpp 2
+ \snippet transform/main.cpp 2
\endtable
\sa QPainter, {Coordinate System}, {painting/affine}{Affine
The rectangle's coordinates are transformed using the following
formulas:
- \snippet doc/src/snippets/code/src_gui_painting_qtransform.cpp 1
+ \snippet code/src_gui_painting_qtransform.cpp 1
Polygons and rectangles behave slightly differently when
transformed (due to integer rounding), so
The rectangle's coordinates are transformed using the following
formulas:
- \snippet doc/src/snippets/code/src_gui_painting_qtransform.cpp 2
+ \snippet code/src_gui_painting_qtransform.cpp 2
If rotation or shearing has been specified, this function returns
the \e bounding rectangle. To retrieve the exact region the given
The coordinates are transformed using the following formulas:
- \snippet doc/src/snippets/code/src_gui_painting_qtransform.cpp 3
+ \snippet code/src_gui_painting_qtransform.cpp 3
The point (x, y) is the original point, and (x', y') is the
transformed point.
Create QFonts like this:
- \snippet doc/src/snippets/code/src_gui_text_qfont.cpp 0
+ \snippet code/src_gui_text_qfont.cpp 0
The attributes set in the constructor can also be set later, e.g.
setFamily(), setPointSize(), setPointSizeFloat(), setWeight() and
Examples:
- \snippet doc/src/snippets/code/src_gui_text_qfont.cpp 1
+ \snippet code/src_gui_text_qfont.cpp 1
If you had both an Adobe and a Cronyx Helvetica, you might get
either.
- \snippet doc/src/snippets/code/src_gui_text_qfont.cpp 2
+ \snippet code/src_gui_text_qfont.cpp 2
You can specify the foundry you want in the family name. The font f
in the above example will be set to "Helvetica
To determine the attributes of the font actually used in the window
system, use a QFontInfo object, e.g.
- \snippet doc/src/snippets/code/src_gui_text_qfont.cpp 3
+ \snippet code/src_gui_text_qfont.cpp 3
To find out font metrics use a QFontMetrics object, e.g.
- \snippet doc/src/snippets/code/src_gui_text_qfont.cpp 4
+ \snippet code/src_gui_text_qfont.cpp 4
For more general information on fonts, see the
\link http://nwalsh.com/comp.fonts/FAQ/ comp.fonts FAQ.\endlink
Example:
- \snippet doc/src/snippets/qfontdatabase/main.cpp 0
- \snippet doc/src/snippets/qfontdatabase/main.cpp 1
+ \snippet qfontdatabase/main.cpp 0
+ \snippet qfontdatabase/main.cpp 1
This example gets the list of font families, the list of
styles for each family, and the point sizes that are available for
and size(), to return the size of that rectangle.
Example:
- \snippet doc/src/snippets/code/src_gui_text_qfontmetrics.cpp 0
+ \snippet code/src_gui_text_qfontmetrics.cpp 0
\sa QFont, QFontInfo, QFontDatabase, QFontComboBox, {Character Map Example}
*/
and size(), to return the size of that rectangle.
Example:
- \snippet doc/src/snippets/code/src_gui_text_qfontmetrics.cpp 1
+ \snippet code/src_gui_text_qfontmetrics.cpp 1
\sa QFont QFontInfo QFontDatabase
*/
pass it the QTextEdit or QTextDocument that you want the syntax
highlighting to be applied to. For example:
- \snippet doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp 0
+ \snippet code/src_gui_text_qsyntaxhighlighter.cpp 0
After this your highlightBlock() function will be called
automatically whenever necessary. Use your highlightBlock()
setFormat() function which applies a given QTextCharFormat on
the current text block. For example:
- \snippet doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp 1
+ \snippet code/src_gui_text_qsyntaxhighlighter.cpp 1
Some syntaxes can have constructs that span several text
blocks. For example, a C++ syntax highlighter should be able to
For example, if you're writing a simple C++ syntax highlighter,
you might designate 1 to signify "in comment":
- \snippet doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp 2
+ \snippet code/src_gui_text_qsyntaxhighlighter.cpp 2
In the example above, we first set the current block state to
0. Then, if the previous block ended within a comment, we higlight
setFormat() as often as necessary to apply any font and color
changes that you require. For example:
- \snippet doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp 3
+ \snippet code/src_gui_text_qsyntaxhighlighter.cpp 3
Some syntaxes can have constructs that span several text
blocks. For example, a C++ syntax highlighter should be able to
and store their relative position and the actual QChar in a simple
class derived from QTextBlockUserData:
- \snippet doc/src/snippets/code/src_gui_text_qsyntaxhighlighter.cpp 4
+ \snippet code/src_gui_text_qsyntaxhighlighter.cpp 4
During cursor navigation in the associated editor, you can ask the
current QTextBlock (retrieved using the QTextCursor::block()
diacritics). Functions such as movePosition() and deleteChar()
limit cursor movement to these valid positions.
- \sa \link richtext.html Rich Text Processing\endlink
+ \sa {Rich Text Processing}
*/
If there is a selection, the selection is deleted and replaced by
\a text, for example:
- \snippet doc/src/snippets/code/src_gui_text_qtextcursor.cpp 0
+ \snippet code/src_gui_text_qtextcursor.cpp 0
This clears any existing selection, selects the word at the cursor
(i.e. from position() forward), and replaces the selection with
the phrase "Hello World".
Convenience method for inserting the image with the given \a name at the
current position().
- \snippet doc/src/snippets/code/src_gui_text_qtextcursor.cpp 1
+ \snippet code/src_gui_text_qtextcursor.cpp 1
*/
void QTextCursor::insertImage(const QString &name)
{
For example:
- \snippet doc/src/snippets/code/src_gui_text_qtextcursor.cpp 2
+ \snippet code/src_gui_text_qtextcursor.cpp 2
The call to undo() will cause both insertions to be undone,
causing both "World" and "Hello" to be removed.
For example:
- \snippet doc/src/snippets/code/src_gui_text_qtextcursor.cpp 3
+ \snippet code/src_gui_text_qtextcursor.cpp 3
The call to undo() will cause all three insertions to be undone.
This function returns a block to test for the end of the document
while iterating over it.
- \snippet doc/src/snippets/textdocumentendsnippet.cpp 0
+ \snippet textdocumentendsnippet.cpp 0
The block returned is invalid and represents the block after the
last block in the document. You can use lastBlock() to retrieve the
For example, you can add an image as a resource in order to reference it
from within the document:
- \snippet snippets/textdocument-resources/main.cpp Adding a resource
+ \snippet textdocument-resources/main.cpp Adding a resource
The image can be inserted into the document using the QTextCursor API:
- \snippet snippets/textdocument-resources/main.cpp Inserting an image with a cursor
+ \snippet textdocument-resources/main.cpp Inserting an image with a cursor
Alternatively, you can insert images using the HTML \c img tag:
- \snippet snippets/textdocument-resources/main.cpp Inserting an image using HTML
+ \snippet textdocument-resources/main.cpp Inserting an image using HTML
*/
void QTextDocument::addResource(int type, const QUrl &name, const QVariant &resource)
{
The \a encoding parameter specifies the value for the charset attribute
in the html header. For example if 'utf-8' is specified then the
beginning of the generated html will look like this:
- \snippet doc/src/snippets/code/src_gui_text_qtextdocument.cpp 0
+ \snippet code/src_gui_text_qtextdocument.cpp 0
If no encoding is specified then no such meta information is generated.
Sets the format used to write documents to the \a format specified.
\a format is a case insensitive text string. For example:
- \snippet doc/src/snippets/code/src.gui.text.qtextdocumentwriter.cpp 0
+ \snippet code/src_gui_text_qtextdocumentwriter.cpp 0
You can call supportedDocumentFormats() for the full list of formats
QTextDocumentWriter supports.
can be used to customize the numbers used in an ordered list so that they
appear as (1), (2), (3), etc.:
- \snippet doc/src/snippets/textdocument-listitemstyles/mainwindow.cpp add a styled, ordered list
+ \snippet textdocument-listitemstyles/mainwindow.cpp add a styled, ordered list
\sa QTextList
*/
created lines.
Here is a code snippet that demonstrates the layout phase:
- \snippet doc/src/snippets/code/src_gui_text_qtextlayout.cpp 0
+ \snippet code/src_gui_text_qtextlayout.cpp 0
The text can then be rendered by calling the layout's draw() function:
- \snippet doc/src/snippets/code/src_gui_text_qtextlayout.cpp 1
+ \snippet code/src_gui_text_qtextlayout.cpp 1
For a given position in the text you can find a valid cursor position with
isValidCursorPosition(), nextCursorPosition(), and previousCursorPosition().
The \l{QTextCursor::insertList()} function inserts an empty block into the
document at the cursor position, and makes it the first item in a list.
- \snippet doc/src/snippets/textdocument-lists/mainwindow.cpp 0
+ \snippet textdocument-lists/mainwindow.cpp 0
The \l{QTextCursor::createList()} function takes the contents of the
cursor's current block and turns it into the first item of a new list.
An iterator can be constructed and used to access the fragments within
a text block in the following way:
- \snippet doc/src/snippets/textblock-fragments/xmlwriter.cpp 4
- \snippet doc/src/snippets/textblock-fragments/xmlwriter.cpp 7
+ \snippet textblock-fragments/xmlwriter.cpp 4
+ \snippet textblock-fragments/xmlwriter.cpp 7
\sa QTextFragment
*/
For example, we can insert a table with three rows and two columns at the
current cursor position in an editor using the following lines of code:
- \snippet doc/src/snippets/textdocument-tables/mainwindow.cpp 1
+ \snippet textdocument-tables/mainwindow.cpp 1
\codeline
- \snippet doc/src/snippets/textdocument-tables/mainwindow.cpp 3
+ \snippet textdocument-tables/mainwindow.cpp 3
The table format is either defined when the table is created or changed
later with setFormat().
\li Suppose we have a 2x3 table of names and addresses. To merge both
columns in the first row we invoke mergeCells() with \a row = 0,
\a column = 0, \a numRows = 1 and \a numColumns = 2.
- \snippet doc/src/snippets/textdocument-texttable/main.cpp 0
+ \snippet textdocument-texttable/main.cpp 0
\row
\li \inlineimage texttable-merge.png
\li This gives us the following table. To split the first row of the table
back into two cells, we invoke the splitCell() function with \a numRows
and \a numCols = 1.
- \snippet doc/src/snippets/textdocument-texttable/main.cpp 1
+ \snippet textdocument-texttable/main.cpp 1
\row
\li \inlineimage texttable-split.png Split Table
URLs, and by registering a handler it becomes possible to display the help text
inside the application:
- \snippet doc/src/snippets/code/src_gui_util_qdesktopservices.cpp 0
+ \snippet code/src_gui_util_qdesktopservices.cpp 0
If inside the handler you decide that you can't open the requested
URL, you can just call QDesktopServices::openUrl() again with the
The following example opens a file on the Windows file system residing on a path
that contains spaces:
- \snippet doc/src/snippets/code/src_gui_util_qdesktopservices.cpp 2
+ \snippet code/src_gui_util_qdesktopservices.cpp 2
If a \c mailto URL is specified, the user's e-mail client will be used to open a
composer window containing the options specified in the URL, similar to the way
For example, the following URL contains a recipient (\c{user@foo.com}), a
subject (\c{Test}), and a message body (\c{Just a test}):
- \snippet doc/src/snippets/code/src_gui_util_qdesktopservices.cpp 1
+ \snippet code/src_gui_util_qdesktopservices.cpp 1
\warning Although many e-mail clients can send attachments and are
Unicode-aware, the user may have configured their client without these features.
Example of use:
- \snippet doc/src/snippets/code/src_gui_widgets_qvalidator.cpp 0
+ \snippet code/src_gui_util_qvalidator.cpp 0
Below we present some examples of validators. In practice they would
normally be associated with a widget as in the example above.
- \snippet doc/src/snippets/code/src_gui_widgets_qvalidator.cpp 1
+ \snippet code/src_gui_util_qvalidator.cpp 1
Notice that the value \c 999 returns Intermediate. Values
consisting of a number of digits equal to or less than the max
the user might be just about to type the minus (especially for right-to-left
languages).
- \snippet doc/src/snippets/code/src_gui_widgets_qvalidator.cpp 2
+ \snippet code/src_gui_util_qvalidator.cpp 2
By default, the \a pos parameter is not used by this validator.
*/
For a brief introduction to Qt's regexp engine, see \l QRegExp.
Example of use:
- \snippet doc/src/snippets/code/src_gui_widgets_qvalidator.cpp 3
+ \snippet code/src_gui_util_qvalidator.cpp 3
Below we present some examples of validators. In practice they would
normally be associated with a widget as in the example above.
- \snippet doc/src/snippets/code/src_gui_widgets_qvalidator.cpp 4
+ \snippet code/src_gui_util_qvalidator.cpp 4
\sa QRegExp, QIntValidator, QDoubleValidator, {Settings Editor Example}
*/