QtBase
v6.3.1
|
The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display formatted text. More...
#include <qgraphicsitem.h>
Signals | |
void | linkActivated (const QString &) |
void | linkHovered (const QString &) |
Signals inherited from QGraphicsObject | |
void | parentChanged () |
void | opacityChanged () |
void | visibleChanged () |
void | enabledChanged () |
void | xChanged () |
void | yChanged () |
void | zChanged () |
void | rotationChanged () |
void | scaleChanged () |
void | childrenChanged () |
void | widthChanged () |
void | heightChanged () |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
Friends | |
class | QGraphicsTextItemPrivate |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
Static Public Member Functions inherited from QObject | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection) |
static QMetaObject::Connection ::type | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot) |
static QMetaObject::Connection ::type | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot) |
template<typename Func1 , typename Func2 > | |
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Protected Types inherited from QGraphicsItem | |
enum | Extension { UserExtension = 0x80000000 } |
Protected Slots inherited from QGraphicsObject | |
void | updateMicroFocus () |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Protected Attributes inherited from QGraphicsItem | |
QScopedPointer< QGraphicsItemPrivate > | d_ptr |
Properties inherited from QGraphicsObject | |
QGraphicsObject * | parent |
the parent of the item More... | |
qreal | opacity |
the opacity of the item More... | |
bool | enabled |
whether the item is enabled or not More... | |
bool | visible |
whether the item is visible or not More... | |
QPointF | pos |
the position of the item More... | |
qreal | x |
the x position of the item More... | |
qreal | y |
the y position of the item More... | |
qreal | z |
the z value of the item More... | |
qreal | rotation |
the rotation of the item in degrees. More... | |
qreal | scale |
the scale of the item. More... | |
QPointF | transformOriginPoint |
the transformation origin More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
Related Functions inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
Related Functions inherited from QGraphicsItem | |
T | qgraphicsitem_cast (QGraphicsItem *item) |
The QGraphicsTextItem class provides a text item that you can add to a QGraphicsScene to display formatted text.
\inmodule QtWidgets
If you only need to show plain text in an item, consider using QGraphicsSimpleTextItem instead.
To set the item's text, pass a QString to QGraphicsTextItem's constructor, or call setHtml()/setPlainText().
QGraphicsTextItem uses the text's formatted size and the associated font to provide a reasonable implementation of boundingRect(), shape(), and contains(). You can set the font by calling setFont().
It is possible to make the item editable by setting the Qt::TextEditorInteraction flag using setTextInteractionFlags().
The item's preferred text width can be set using setTextWidth() and obtained using textWidth().
Definition at line 857 of file qgraphicsitem.h.
anonymous enum |
Enumerator | |
---|---|
Type |
Definition at line 889 of file qgraphicsitem.h.
|
explicit |
Constructs a QGraphicsTextItem. parent is passed to QGraphicsItem's constructor.
Definition at line 9804 of file qgraphicsitem.cpp.
|
explicit |
Constructs a QGraphicsTextItem, using text as the default plain text. parent is passed to QGraphicsItem's constructor.
Definition at line 9786 of file qgraphicsitem.cpp.
QGraphicsTextItem::~QGraphicsTextItem | ( | ) |
Destroys the QGraphicsTextItem.
Definition at line 9817 of file qgraphicsitem.cpp.
void QGraphicsTextItem::adjustSize | ( | ) |
Adjusts the text item to a reasonable size.
Definition at line 10040 of file qgraphicsitem.cpp.
|
overridevirtual |
\reimp
Implements QGraphicsItem.
Definition at line 9919 of file qgraphicsitem.cpp.
\reimp
Reimplemented from QGraphicsItem.
Definition at line 9939 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10200 of file qgraphicsitem.cpp.
QColor QGraphicsTextItem::defaultTextColor | ( | ) | const |
Returns the default text color that is used for unformatted text.
Definition at line 9911 of file qgraphicsitem.cpp.
QTextDocument * QGraphicsTextItem::document | ( | ) | const |
Returns the item's text document.
Definition at line 10058 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10245 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10253 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10261 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10269 of file qgraphicsitem.cpp.
Reimplemented from QGraphicsItem.
Definition at line 10350 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Reimplemented in FocusItem.
Definition at line 10224 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Reimplemented in FocusItem.
Definition at line 10236 of file qgraphicsitem.cpp.
QFont QGraphicsTextItem::font | ( | ) | const |
Returns the item's font, which is used to render the text.
Definition at line 9877 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10285 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10301 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10293 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10277 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10309 of file qgraphicsitem.cpp.
|
overridevirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 9980 of file qgraphicsitem.cpp.
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10208 of file qgraphicsitem.cpp.
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10216 of file qgraphicsitem.cpp.
This signal is emitted when the user clicks on a link on a text item that enables Qt::LinksAccessibleByMouse or Qt::LinksAccessibleByKeyboard. link is the link that was clicked.
This signal is emitted when the user hovers over a link on a text item that enables Qt::LinksAccessibleByMouse. link is the link that was hovered over.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10182 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10143 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10118 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10156 of file qgraphicsitem.cpp.
|
overridevirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 9988 of file qgraphicsitem.cpp.
bool QGraphicsTextItem::openExternalLinks | ( | ) | const |
Specifies whether QGraphicsTextItem should automatically open links using QDesktopServices::openUrl() instead of emitting the linkActivated signal.
The default value is false.
Definition at line 10542 of file qgraphicsitem.cpp.
|
overridevirtual |
\reimp
Implements QGraphicsItem.
Reimplemented in QGraphicsTextItem_task172231.
Definition at line 9947 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
\reimp
Reimplemented from QGraphicsItem.
Definition at line 10066 of file qgraphicsitem.cpp.
Sets the color for unformatted text to col.
Definition at line 9897 of file qgraphicsitem.cpp.
void QGraphicsTextItem::setDocument | ( | QTextDocument * | document | ) |
Sets the text document document on the item.
Definition at line 10049 of file qgraphicsitem.cpp.
|
overrideprotectedvirtual |
Reimplemented from QGraphicsItem.
Definition at line 10341 of file qgraphicsitem.cpp.
Sets the font used to render the text item to font.
Definition at line 9889 of file qgraphicsitem.cpp.
Sets the item's text to text, assuming that text is HTML formatted. If the item has keyboard input focus, this function will also call ensureVisible() to ensure that the text is visible in all viewports.
Definition at line 9843 of file qgraphicsitem.cpp.
void QGraphicsTextItem::setOpenExternalLinks | ( | bool | open | ) |
Sets the item's text to text. If the item has keyboard input focus, this function will also call ensureVisible() to ensure that the text is visible in all viewports.
Definition at line 9867 of file qgraphicsitem.cpp.
void QGraphicsTextItem::setTabChangesFocus | ( | bool | b | ) |
If b is true, the \uicontrol Tab key will cause the widget to change focus; otherwise, the tab key will insert a tab into the document.
In some occasions text edits should not allow the user to input tabulators or change indentation using the \uicontrol Tab key, as this breaks the focus chain. The default is false.
Definition at line 10508 of file qgraphicsitem.cpp.
void QGraphicsTextItem::setTextCursor | ( | const QTextCursor & | cursor | ) |
void QGraphicsTextItem::setTextInteractionFlags | ( | Qt::TextInteractionFlags | flags | ) |
Sets the flags flags to specify how the text item should react to user input.
The default for a QGraphicsTextItem is Qt::NoTextInteraction. This function also affects the ItemIsFocusable QGraphicsItem flag by setting it if flags is different from Qt::NoTextInteraction and clearing it otherwise.
By default, the text is read-only. To transform the item into an editor, set the Qt::TextEditable flag.
Definition at line 10474 of file qgraphicsitem.cpp.
Sets the preferred width for the item's text. If the actual text is wider than the specified width then it will be broken into multiple lines.
If width is set to -1 then the text will not be broken into multiple lines unless it is enforced through an explicit line break or a new paragraph.
The default value is -1.
Note that QGraphicsTextItem keeps a QTextDocument internally, which is used to calculate the text width.
Definition at line 10017 of file qgraphicsitem.cpp.
|
overridevirtual |
|
overrideprotectedvirtual |
Reimplemented from QGraphicsItem.
Definition at line 10332 of file qgraphicsitem.cpp.
bool QGraphicsTextItem::tabChangesFocus | ( | ) | const |
Returns true
if the \uicontrol Tab key will cause the widget to change focus; otherwise, false is returned.
By default, this behavior is disabled, and this function will return false.
Definition at line 10523 of file qgraphicsitem.cpp.
QTextCursor QGraphicsTextItem::textCursor | ( | ) | const |
This property represents the visible text cursor in an editable text item.
By default, if the item's text has not been set, this property contains a null text cursor; otherwise it contains a text cursor placed at the start of the item's document.
Definition at line 10564 of file qgraphicsitem.cpp.
Qt::TextInteractionFlags QGraphicsTextItem::textInteractionFlags | ( | ) | const |
Returns the current text interaction flags.
Definition at line 10489 of file qgraphicsitem.cpp.
qreal QGraphicsTextItem::textWidth | ( | ) | const |
Returns the text width.
The width is calculated with the QTextDocument that QGraphicsTextItem keeps internally.
Definition at line 10030 of file qgraphicsitem.cpp.
QString QGraphicsTextItem::toHtml | ( | ) | const |
Returns the item's text converted to HTML, or an empty QString if no text has been set.
Definition at line 9827 of file qgraphicsitem.cpp.
QString QGraphicsTextItem::toPlainText | ( | ) | const |
Returns the item's text converted to plain text, or an empty QString if no text has been set.
Definition at line 9853 of file qgraphicsitem.cpp.
|
overridevirtual |
|
friend |
Definition at line 945 of file qgraphicsitem.h.