Hi there,

I think my problem is rather trivial: I want to insert QCPItemText objects in my plot and implement functionality that makes it possible to move such objects freely around using drag 'n drop. In the QCustomPlot discussion forum I found this thread which describes analoguous functionality for the movement of a legend:


Following this example I started the implementation of the drag'n drop based movement of a QCPItemText object:

1. I added these two member variables to the plot's class (PlotUI inherits from QCustomPlot):

    bool mDraggingTextbox;
    QPointF mDragTextboxOrigin;

2. In the plot's constructor I added these connect statements:

connect(this, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(handleMousePress(QMouseEvent*)));
connect(this, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(handleMouseMove(QMouseEvent*)));
connect(this, SIGNAL(mouseRelease(QMouseEvent*)), this, SLOT(handleMouseRelease(QMouseEvent*)));

3. The slot method handleMousePress(QMouseEvent*) looks as follows
(class TextBoxUI inherits from QCPItemText):

void PlotUI::handleMousePress(QMouseEvent *event) {
    for (vector<TextboxUI*>::size_type i = 0; i < mTextboxes.size(); ++i) {
        TextboxUI *tbUI(mTextboxes.at(i));
        if (tbUI->selectTest(event->pos(), false) > 0) {
            mDraggingTextbox = true;
            mDragTextboxOrigin = tbUI->topLeft->pixelPosition();

4. The slot method handleMouseRelease(QMouseEvent *event) looks as

void PlotUI::handleMouseRelease(QMouseEvent *event) {
    mDraggingTextbox = false;

5. My problem is how to implement the slot method

void PlotUI::handleMouseMove(QMouseEvent *event) {
    if (mDraggingTextbox) {

    // ???


I checked the QCPItemText class's API but could not figure out how the
moving of the text box is to be implemented.

Any help is highly appreciated!