1

I am trying add a text item onto a QCustomPlot widget. The QCPItemText constructor takes a pointer to QCustomPlot widget as an argument.

QCPItemText::QCPItemText ( QCustomPlot * parentPlot)

After creating the QCPItemText object, it can added to the widget by using the member function, QCustomPlot::addItem(). But my problem is the program doesn't compile. It says there no member function called QCustomPlot::addItem(). But this example seems do this. I am confused.

This is part of my code;

    //hash out current widget
    QCustomPlot *currentWidget = GraphWindow::dynamicWidgetHash.value(slot);

   //Setup font
    QFont plotFont;
    plotFont.setStyleHint(QFont::Helvetica);
    plotFont.setBold(true);
    plotFont.setWeight(8);
    plotFont.setPointSize(16);

    GraphWindow::setupBackground(slot);        
    QCPItemText itemText(currentWidget);
    QString dataText = "No " + xLabel + " data found. \nPossibly the firm may not possess " + xLabel;
    itemText.setText(dataText);
    itemText.setPositionAlignment(Qt::AlignTop|Qt::AlignCenter);
    itemText.position->setType(QCPItemPosition::ptAxisRectRatio);
    itemText.position->setCoords(2,2);
    itemText.setFont(plotFont);
    itemText.setPen(QPen(Qt::white));

Where dynamicWidgetHash is a QHash object, which stores a QCustomPlot * for each given key.

The error occurs when I try to use this line

currentWidget->addIem(itemText);

1 Answer 1

1

On line 79 in the changelog.txt file, which exists in the QcustomPlot install path, you'll see that it reads:

Removed QCustomPlot::addItem, not needed anymore as items now automatically register in their constructor.

So you don't need currentWidget->addIem(itemText);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.