#include <vtkQtChartMouseBox.h>
To use the vtkQtChartMouseBox, code needs to be added to several key methods. The drag box interaction starts in the mouse press event. The box grows or shrinks in the mouse move event. In the mouse release event, the box is finalized and used for its intent (zoom, select, etc.).
In the mouse press event, the mouse location needs to be saved. The position should be in the mouse box's parent coordinates.
void SomeClass::mousePressEvent(QMouseEvent *e) { this->mouseBox->setStartingPosition(e->pos()); this->mouseBox->setVisible(true); }
In the mouse move event, the drag box needs to be updated. The point set in the mouse press event should remain unchanged until the mouse release event. If your class watches all mouse move events, make sure the box is only updated for drag events.
void SomeClass::mouseMoveEvent(QMouseEvent *e)
{
this->mouseBox->adjustRectangle(e->pos());
}
In the mouse release event, the drag box needs to be updated with the release location before using it. After using the box, it should be hidden.
void SomeClass::mouseReleaseEvent(QMouseEvent *e) { this->mouseBox->adjustRectangle(e->pos()); ... this->mouseBox->setVisible(false); }
Definition at line 82 of file vtkQtChartMouseBox.h.
Signals | |
void | updateNeeded (const QRectF &area) |
Public Member Functions | |
vtkQtChartMouseBox (QGraphicsView *view) | |
~vtkQtChartMouseBox () | |
bool | isVisible () const |
Gets whether or not the mouse box is visible. | |
void | setVisible (bool visible) |
Sets whether or not the mouse box is visible. | |
const QPointF & | getStartingPosition () const |
Gets the mouse box starting position. | |
void | setStartingPosition (const QPoint &start) |
Sets the mouse box starting position. | |
void | adjustRectangle (const QPoint ¤t) |
Adjusts the boundary of the mouse box. | |
const QRectF & | getRectangle () const |
Gets the current mouse box. |
vtkQtChartMouseBox::vtkQtChartMouseBox | ( | QGraphicsView * | view | ) |
vtkQtChartMouseBox::~vtkQtChartMouseBox | ( | ) |
bool vtkQtChartMouseBox::isVisible | ( | ) | const [inline] |
Gets whether or not the mouse box is visible.
Definition at line 94 of file vtkQtChartMouseBox.h.
void vtkQtChartMouseBox::setVisible | ( | bool | visible | ) |
Sets whether or not the mouse box is visible.
visible | True if the mouse box should be painted. |
const QPointF& vtkQtChartMouseBox::getStartingPosition | ( | ) | const |
Gets the mouse box starting position.
void vtkQtChartMouseBox::setStartingPosition | ( | const QPoint & | start | ) |
Sets the mouse box starting position.
The starting position should be set before calling adjustRectangle
. The starting position and adjustment positions should be in view coordinates.
start | The original mouse press location in view coordinates. |
void vtkQtChartMouseBox::adjustRectangle | ( | const QPoint & | current | ) |
Adjusts the boundary of the mouse box.
The selection or zoom box should contain the original mouse down location and the current mouse location. This method is used to adjust the box based on the current mouse location.
current | The current position of the mouse in view coordinates. |
const QRectF& vtkQtChartMouseBox::getRectangle | ( | ) | const |
Gets the current mouse box.
void vtkQtChartMouseBox::updateNeeded | ( | const QRectF & | area | ) | [signal] |