QCPAbstractItem

Search for usage in LXR

Inheritance diagram for QCPAbstractItem:

Signals

void selectableChanged (bool selectable)
 
void selectionChanged (bool selected)
 
- Signals inherited from QCPLayerable
void layerChanged (QCPLayer *newLayer)
 

Public Member Functions

 QCPAbstractItem (QCustomPlot *parentPlot)
 
QCPItemAnchoranchor (const QString &name) const
 
QList< QCPItemAnchor * > anchors () const
 
QCPAxisRectclipAxisRect () const
 
bool clipToAxisRect () const
 
bool hasAnchor (const QString &name) const
 
QCPItemPositionposition (const QString &name) const
 
QList< QCPItemPosition * > positions () const
 
bool selectable () const
 
bool selected () const
 
virtual double selectTest (const QPointF &pos, bool onlySelectable, QVariant *details=nullptr) const override=0
 
void setClipAxisRect (QCPAxisRect *rect)
 
void setClipToAxisRect (bool clip)
 
Q_SLOT void setSelectable (bool selectable)
 
Q_SLOT void setSelected (bool selected)
 
- Public Member Functions inherited from QCPLayerable
 QCPLayerable (QCustomPlot *plot, QString targetLayer=QString(), QCPLayerable *parentLayerable=nullptr)
 
bool antialiased () const
 
QCPLayerlayer () const
 
QCPLayerableparentLayerable () const
 
QCustomPlotparentPlot () const
 
bool realVisibility () const
 
void setAntialiased (bool enabled)
 
bool setLayer (const QString &layerName)
 
Q_SLOT bool setLayer (QCPLayer *layer)
 
void setVisible (bool on)
 
bool visible () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
QBindable< QStringbindableObjectName ()
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo () const const
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isQuickItemType () const const
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_GADGET_EXPORT (EXPORT_MACRO)
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_MOC_INCLUDE Q_MOC_INCLUDE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setObjectName (QAnyStringView name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool setProperty (const char *name, QVariant &&value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds interval, Qt::TimerType timerType)
 
QThreadthread () const const
 

Protected Member Functions

virtual QPointF anchorPixelPosition (int anchorId) const
 
virtual void applyDefaultAntialiasingHint (QCPPainter *painter) const override
 
virtual QRect clipRect () const override
 
QCPItemAnchorcreateAnchor (const QString &name, int anchorId)
 
QCPItemPositioncreatePosition (const QString &name)
 
virtual void deselectEvent (bool *selectionStateChanged) override
 
virtual void draw (QCPPainter *painter) override=0
 
double rectDistance (const QRectF &rect, const QPointF &pos, bool filledRect) const
 
virtual void selectEvent (QMouseEvent *event, bool additive, const QVariant &details, bool *selectionStateChanged) override
 
virtual QCP::Interaction selectionCategory () const override
 
- Protected Member Functions inherited from QCPLayerable
void applyAntialiasingHint (QCPPainter *painter, bool localAntialiased, QCP::AntialiasedElement overrideElement) const
 
void initializeParentPlot (QCustomPlot *parentPlot)
 
virtual void mouseDoubleClickEvent (QMouseEvent *event, const QVariant &details)
 
virtual void mouseMoveEvent (QMouseEvent *event, const QPointF &startPos)
 
virtual void mousePressEvent (QMouseEvent *event, const QVariant &details)
 
virtual void mouseReleaseEvent (QMouseEvent *event, const QPointF &startPos)
 
bool moveToLayer (QCPLayer *layer, bool prepend)
 
virtual void parentPlotInitialized (QCustomPlot *parentPlot)
 
void setParentLayerable (QCPLayerable *parentLayerable)
 
virtual void wheelEvent (QWheelEvent *event)
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Protected Attributes

QList< QCPItemAnchor * > mAnchors
 
QPointer< QCPAxisRectmClipAxisRect
 
bool mClipToAxisRect
 
QList< QCPItemPosition * > mPositions
 
bool mSelectable
 
bool mSelected
 
- Protected Attributes inherited from QCPLayerable
bool mAntialiased
 
QCPLayermLayer
 
QPointer< QCPLayerablemParentLayerable
 
QCustomPlotmParentPlot
 
bool mVisible
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

The abstract base class for all items in a plot.

In QCustomPlot, items are supplemental graphical elements that are neither plottables (QCPAbstractPlottable) nor axes (QCPAxis). While plottables are always tied to two axes and thus plot coordinates, items can also be placed in absolute coordinates independent of any axes. Each specific item has at least one QCPItemPosition member which controls the positioning. Some items are defined by more than one coordinate and thus have two or more QCPItemPosition members (For example, QCPItemRect has topLeft and bottomRight).

This abstract base class defines a very basic interface like visibility and clipping. Since this class is abstract, it can't be instantiated. Use one of the subclasses or create a subclass yourself to create new items.

The built-in items are:

QCPItemLineA line defined by a start and an end point. May have different ending styles on each side (e.g. arrows).
QCPItemStraightLineA straight line defined by a start and a direction point. Unlike QCPItemLine, the straight line is infinitely long and has no endings.
QCPItemCurveA curve defined by start, end and two intermediate control points. May have different ending styles on each side (e.g. arrows).
QCPItemRectA rectangle
QCPItemEllipseAn ellipse
QCPItemPixmapAn arbitrary pixmap
QCPItemTextA text label
QCPItemBracketA bracket which may be used to reference/highlight certain parts in the plot.
QCPItemTracerAn item that can be attached to a QCPGraph and sticks to its data points, given a key coordinate.

Clipping

Items are by default clipped to the main axis rect (they are only visible inside the axis rect). To make an item visible outside that axis rect, disable clipping via setClipToAxisRect(false).

On the other hand if you want the item to be clipped to a different axis rect, specify it via setClipAxisRect. This clipAxisRect property of an item is only used for clipping behaviour, and in principle is independent of the coordinate axes the item might be tied to via its position members (QCPItemPosition::setAxes). However, it is common that the axis rect for clipping also contains the axes used for the item positions.

Using items

First you instantiate the item you want to use and add it to the plot:

by default, the positions of the item are bound to the x- and y-Axis of the plot. So we can just set the plot coordinates where the line should start/end:

If we don't want the line to be positioned in plot coordinates but a different coordinate system, e.g. absolute pixel positions on the QCustomPlot surface, we need to change the position type like this:

Then we can set the coordinates, this time in pixels:

and make the line visible on the entire QCustomPlot, by disabling clipping to the axis rect:

For more advanced plots, it is even possible to set different types and parent anchors per X/Y coordinate of an item position, using for example QCPItemPosition::setTypeX or QCPItemPosition::setParentAnchorX. For details, see the documentation of QCPItemPosition.

Creating own items

To create an own item, you implement a subclass of QCPAbstractItem. These are the pure virtual functions, you must implement:

See the documentation of those functions for what they need to do.

Allowing the item to be positioned

As mentioned, item positions are represented by QCPItemPosition members. Let's assume the new item shall have only one point as its position (as opposed to two like a rect or multiple like a polygon). You then add a public member of type QCPItemPosition like so:

Manages the position of an item.

the const makes sure the pointer itself can't be modified from the user of your new item (the QCPItemPosition instance it points to, can be modified, of course). The initialization of this pointer is made easy with the createPosition function. Just assign the return value of this function to each QCPItemPosition in the constructor of your item. createPosition takes a string which is the name of the position, typically this is identical to the variable name. For example, the constructor of QCPItemExample could look like this:

QCPAbstractItem(parentPlot),
myPosition(createPosition("myPosition"))
{
// other constructor code
}
The abstract base class for all items in a plot.
QCPItemPosition * createPosition(const QString &name)
The central class of the library. This is the QWidget which displays the plot and interacts with the ...

The draw function

To give your item a visual representation, reimplement the draw function and use the passed QCPPainter to draw the item. You can retrieve the item position in pixel coordinates from the position member(s) via QCPItemPosition::pixelPosition.

To optimize performance you should calculate a bounding rect first (don't forget to take the pen width into account), check whether it intersects the clipRect, and only draw the item at all if this is the case.

The selectTest function

Your implementation of the selectTest function may use the helpers QCPVector2D::distanceSquaredToLine and rectDistance. With these, the implementation of the selection test becomes significantly simpler for most items. See the documentation of selectTest for what the function parameters mean and what the function should return.

Providing anchors

Providing anchors (QCPItemAnchor) starts off like adding a position. First you create a public member, e.g.

QCPItemAnchor * const bottom;
An anchor of an item to which positions can be attached to.

and create it in the constructor with the createAnchor function, assigning it a name and an anchor id (an integer enumerating all anchors on the item, you may create an own enum for this). Since anchors can be placed anywhere, relative to the item's position(s), your item needs to provide the position of every anchor with the reimplementation of the anchorPixelPosition(int anchorId) function.

In essence the QCPItemAnchor is merely an intermediary that itself asks your item for the pixel position when anything attached to the anchor needs to know the coordinates.

Definition at line 3654 of file qcustomplot.h.

Constructor & Destructor Documentation

◆ QCPAbstractItem()

QCPAbstractItem::QCPAbstractItem ( QCustomPlot * parentPlot)
explicit

Base class constructor which initializes base class members.

Definition at line 12915 of file qcustomplot.cpp.

◆ ~QCPAbstractItem()

QCPAbstractItem::~QCPAbstractItem ( )
overridevirtual

Definition at line 12931 of file qcustomplot.cpp.

Member Function Documentation

◆ anchor()

QCPItemAnchor * QCPAbstractItem::anchor ( const QString & name) const

Returns the QCPItemAnchor with the specified name. If this item doesn't have an anchor by that name, returns nullptr.

This function provides an alternative way to access item anchors. Normally, you access anchors direcly by their member pointers (which typically have the same variable name as name).

See also
anchors, position

Definition at line 13041 of file qcustomplot.cpp.

◆ anchorPixelPosition()

QPointF QCPAbstractItem::anchorPixelPosition ( int anchorId) const
protectedvirtual

Returns the pixel position of the anchor with Id anchorId. This function must be reimplemented in item subclasses if they want to provide anchors (QCPItemAnchor).

For example, if the item has two anchors with id 0 and 1, this function takes one of these anchor ids and returns the respective pixel points of the specified anchor.

See also
createAnchor

Reimplemented in QCPItemRect, QCPItemText, QCPItemEllipse, QCPItemPixmap, and QCPItemBracket.

Definition at line 13154 of file qcustomplot.cpp.

◆ anchors()

QList< QCPItemAnchor * > QCPAbstractItem::anchors ( ) const
inline

Returns all anchors of the item in a list. Note that since a position (QCPItemPosition) is always also an anchor, the list will also contain the positions of this item.

See also
positions, anchor

Definition at line 3684 of file qcustomplot.h.

◆ applyDefaultAntialiasingHint()

void QCPAbstractItem::applyDefaultAntialiasingHint ( QCPPainter * painter) const
overrideprotectedvirtual

A convenience function to easily set the QPainter::Antialiased hint on the provided painter before drawing item lines.

This is the antialiasing state the painter passed to the draw method is in by default.

This function takes into account the local setting of the antialiasing flag as well as the overrides set with QCustomPlot::setAntialiasedElements and QCustomPlot::setNotAntialiasedElements.

See also
setAntialiased

Implements QCPLayerable.

Definition at line 13100 of file qcustomplot.cpp.

◆ clipAxisRect()

QCPAxisRect * QCPAbstractItem::clipAxisRect ( ) const

Definition at line 12938 of file qcustomplot.cpp.

◆ clipRect()

QRect QCPAbstractItem::clipRect ( ) const
overrideprotectedvirtual

Returns the rect the visual representation of this item is clipped to. This depends on the current setting of setClipToAxisRect as well as the axis rect set with setClipAxisRect.

If the item is not clipped to an axis rect, QCustomPlot's viewport rect is returned.

See also
draw

Reimplemented from QCPLayerable.

Definition at line 13079 of file qcustomplot.cpp.

◆ clipToAxisRect()

bool QCPAbstractItem::clipToAxisRect ( ) const
inline

Definition at line 3668 of file qcustomplot.h.

◆ createAnchor()

QCPItemAnchor * QCPAbstractItem::createAnchor ( const QString & name,
int anchorId )
protected

Creates a QCPItemAnchor, registers it with this item and returns a pointer to it. The specified name must be a unique string that is usually identical to the variable name of the anchor member (This is needed to provide the name based anchor access to anchors).

The anchorId must be a number identifying the created anchor. It is recommended to create an enum (e.g. "AnchorIndex") for this on each item that uses anchors. This id is used by the anchor to identify itself when it calls QCPAbstractItem::anchorPixelPosition. That function then returns the correct pixel coordinates for the passed anchor id.

Don't delete anchors created by this function manually, as the item will take care of it.

Use this function in the constructor (initialization list) of the specific item subclass to create each anchor member. Don't create QCPItemAnchors with new yourself, because then they won't be registered with the item properly.

See also
createPosition

Definition at line 13208 of file qcustomplot.cpp.

◆ createPosition()

QCPItemPosition * QCPAbstractItem::createPosition ( const QString & name)
protected

Creates a QCPItemPosition, registers it with this item and returns a pointer to it. The specified name must be a unique string that is usually identical to the variable name of the position member (This is needed to provide the name-based position access to positions).

Don't delete positions created by this function manually, as the item will take care of it.

Use this function in the constructor (initialization list) of the specific item subclass to create each position member. Don't create QCPItemPositions with new yourself, because they won't be registered with the item properly.

See also
createAnchor

Definition at line 13174 of file qcustomplot.cpp.

◆ deselectEvent()

void QCPAbstractItem::deselectEvent ( bool * selectionStateChanged)
overrideprotectedvirtual

This event is called when the layerable shall be deselected, either as consequence of a user interaction or a call to QCustomPlot::deselectAll. Subclasses should react to it by unsetting their selection appropriately.

just as in selectEvent, the output parameter selectionStateChanged (if non-null), must return true or false when the selection state of this layerable has changed or not changed, respectively.

See also
selectTest, selectEvent

Reimplemented from QCPLayerable.

Definition at line 13232 of file qcustomplot.cpp.

◆ draw()

void QCPAbstractItem::draw ( QCPPainter * painter)
overrideprotectedpure virtual

Draws this item with the provided painter.

The cliprect of the provided painter is set to the rect returned by clipRect before this function is called. The clipRect depends on the clipping settings defined by setClipToAxisRect and setClipAxisRect.

Implements QCPLayerable.

Implemented in QCPItemStraightLine, QCPItemLine, QCPItemCurve, QCPItemRect, QCPItemText, QCPItemEllipse, QCPItemPixmap, QCPItemTracer, and QCPItemBracket.

◆ hasAnchor()

bool QCPAbstractItem::hasAnchor ( const QString & name) const

Returns whether this item has an anchor with the specified name.

Note that you can check for positions with this function, too. This is because every position is also an anchor (QCPItemPosition inherits from QCPItemAnchor).

See also
anchor, position

Definition at line 13060 of file qcustomplot.cpp.

◆ position()

QCPItemPosition * QCPAbstractItem::position ( const QString & name) const

Returns the QCPItemPosition with the specified name. If this item doesn't have a position by that name, returns nullptr.

This function provides an alternative way to access item positions. Normally, you access positions direcly by their member pointers (which typically have the same variable name as name).

See also
positions, anchor

Definition at line 13020 of file qcustomplot.cpp.

◆ positions()

QList< QCPItemPosition * > QCPAbstractItem::positions ( ) const
inline

Returns all positions of the item in a list.

See also
anchors, position

Definition at line 3683 of file qcustomplot.h.

◆ rectDistance()

double QCPAbstractItem::rectDistance ( const QRectF & rect,
const QPointF & pos,
bool filledRect ) const
protected

A convenience function which returns the selectTest value for a specified rect and a specified click position pos. filledRect defines whether a click inside the rect should also be considered a hit or whether only the rect border is sensitive to hits.

This function may be used to help with the implementation of the selectTest function for specific items.

For example, if your item consists of four rects, call this function four times, once for each rect, in your selectTest reimplementation. Finally, return the minimum (non -1) of all four returned values.

Definition at line 13118 of file qcustomplot.cpp.

◆ selectable()

bool QCPAbstractItem::selectable ( ) const
inline

Definition at line 3670 of file qcustomplot.h.

◆ selected()

bool QCPAbstractItem::selected ( ) const
inline

Definition at line 3671 of file qcustomplot.h.

◆ selectEvent()

void QCPAbstractItem::selectEvent ( QMouseEvent * event,
bool additive,
const QVariant & details,
bool * selectionStateChanged )
overrideprotectedvirtual

This event is called when the layerable shall be selected, as a consequence of a click by the user. Subclasses should react to it by setting their selection state appropriately. The default implementation does nothing.

event is the mouse event that caused the selection. additive indicates, whether the user was holding the multi-select-modifier while performing the selection (see QCustomPlot::setMultiSelectModifier). if additive is true, the selection state must be toggled (i.e. become selected when unselected and unselected when selected).

Every selectEvent is preceded by a call to selectTest, which has returned positively (i.e. returned a value greater than 0 and less than the selection tolerance of the parent QCustomPlot). The details data you output from selectTest is fed back via details here. You may use it to transport any kind of information from the selectTest to the possibly subsequent selectEvent. Usually details is used to transfer which part was clicked, if it is a layerable that has multiple individually selectable parts (like QCPAxis). This way selectEvent doesn't need to do the calculation again to find out which part was actually clicked.

selectionStateChanged is an output parameter. If the pointer is non-null, this function must set the value either to true or false, depending on whether the selection state of this layerable was actually changed. For layerables that only are selectable as a whole and not in parts, this is simple: if additive is true, selectionStateChanged must also be set to true, because the selection toggles. If additive is false, selectionStateChanged is only set to true, if the layerable was previously unselected and now is switched to the selected state.

See also
selectTest, deselectEvent

Reimplemented from QCPLayerable.

Definition at line 13218 of file qcustomplot.cpp.

◆ selectionCategory()

QCP::Interaction QCPAbstractItem::selectionCategory ( ) const
overrideprotectedvirtual

Returns the selection category this layerable shall belong to. The selection category is used in conjunction with QCustomPlot::setInteractions to control which objects are selectable and which aren't.

Subclasses that don't fit any of the normal QCP::Interaction values can use QCP::iSelectOther. This is what the default implementation returns.

See also
QCustomPlot::setInteractions

Reimplemented from QCPLayerable.

Definition at line 13244 of file qcustomplot.cpp.

◆ selectionChanged

void QCPAbstractItem::selectionChanged ( bool selected)
signal

This signal is emitted when the selection state of this item has changed, either by user interaction or by a direct call to setSelected.

◆ selectTest()

virtual double QCPAbstractItem::selectTest ( const QPointF & pos,
bool onlySelectable,
QVariant * details = nullptr ) const
overridepure virtual

This function is used to decide whether a click hits a layerable object or not.

pos is a point in pixel coordinates on the QCustomPlot surface. This function returns the shortest pixel distance of this point to the object. If the object is either invisible or the distance couldn't be determined, -1.0 is returned. Further, if onlySelectable is true and the object is not selectable, -1.0 is returned, too.

If the object is represented not by single lines but by an area like a QCPItemText or the bars of a QCPBars plottable, a click inside the area should also be considered a hit. In these cases this function thus returns a constant value greater zero but still below the parent plot's selection tolerance. (typically the selectionTolerance multiplied by 0.99).

Providing a constant value for area objects allows selecting line objects even when they are obscured by such area objects, by clicking close to the lines (i.e. closer than 0.99*selectionTolerance).

The actual setting of the selection state is not done by this function. This is handled by the parent QCustomPlot when the mouseReleaseEvent occurs, and the finally selected object is notified via the selectEvent/ deselectEvent methods.

details is an optional output parameter. Every layerable subclass may place any information in details. This information will be passed to selectEvent when the parent QCustomPlot decides on the basis of this selectTest call, that the object was successfully selected. The subsequent call to selectEvent will carry the details. This is useful for multi-part objects (like QCPAxis). This way, a possibly complex calculation to decide which part was clicked is only done once in selectTest. The result (i.e. the actually clicked part) can then be placed in details. So in the subsequent selectEvent, the decision which part was selected doesn't have to be done a second time for a single selection operation.

In the case of 1D Plottables (QCPAbstractPlottable1D, like QCPGraph or QCPBars) details will be set to a QCPDataSelection, describing the closest data point to pos.

You may pass nullptr as details to indicate that you are not interested in those selection details.

See also
selectEvent, deselectEvent, mousePressEvent, wheelEvent, QCustomPlot::setInteractions, QCPAbstractPlottable1D::selectTestRect

Reimplemented from QCPLayerable.

Implemented in QCPItemStraightLine, QCPItemLine, QCPItemCurve, QCPItemRect, QCPItemText, QCPItemEllipse, QCPItemPixmap, QCPItemTracer, and QCPItemBracket.

◆ setClipAxisRect()

void QCPAbstractItem::setClipAxisRect ( QCPAxisRect * rect)

Sets the clip axis rect. It defines the rect that will be used to clip the item when setClipToAxisRect is set to true.

See also
setClipToAxisRect

Definition at line 12962 of file qcustomplot.cpp.

◆ setClipToAxisRect()

void QCPAbstractItem::setClipToAxisRect ( bool clip)

Sets whether the item shall be clipped to an axis rect or whether it shall be visible on the entire QCustomPlot. The axis rect can be set with setClipAxisRect.

See also
setClipAxisRect

Definition at line 12949 of file qcustomplot.cpp.

◆ setSelectable()

void QCPAbstractItem::setSelectable ( bool selectable)

Sets whether the user can (de-)select this item by clicking on the QCustomPlot surface. (When QCustomPlot::setInteractions contains QCustomPlot::iSelectItems.)

However, even when selectable was set to false, it is possible to set the selection manually, by calling setSelected.

See also
QCustomPlot::setInteractions, setSelected

Definition at line 12978 of file qcustomplot.cpp.

◆ setSelected()

void QCPAbstractItem::setSelected ( bool selected)

Sets whether this item is selected or not. When selected, it might use a different visual appearance (e.g. pen and brush), this depends on the specific item though.

The entire selection mechanism for items is handled automatically when QCustomPlot::setInteractions contains QCustomPlot::iSelectItems. You only need to call this function when you wish to change the selection state manually.

This function can change the selection state even when setSelectable was set to false.

emits the selectionChanged signal when selected is different from the previous selection state.

See also
setSelectable, selectTest

Definition at line 13001 of file qcustomplot.cpp.

Member Data Documentation

◆ mAnchors

QList<QCPItemAnchor*> QCPAbstractItem::mAnchors
protected

Definition at line 3698 of file qcustomplot.h.

◆ mClipAxisRect

QPointer<QCPAxisRect> QCPAbstractItem::mClipAxisRect
protected

Definition at line 3696 of file qcustomplot.h.

◆ mClipToAxisRect

bool QCPAbstractItem::mClipToAxisRect
protected

Definition at line 3695 of file qcustomplot.h.

◆ mPositions

QList<QCPItemPosition*> QCPAbstractItem::mPositions
protected

Definition at line 3697 of file qcustomplot.h.

◆ mSelectable

bool QCPAbstractItem::mSelectable
protected

Definition at line 3699 of file qcustomplot.h.

◆ mSelected

bool QCPAbstractItem::mSelected
protected

Definition at line 3699 of file qcustomplot.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:05 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.