Vino
Vino

Reputation: 2311

QCustomPlot adding QCustomItemText

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);

Upvotes: 1

Views: 1285

Answers (1)

张洪杰
张洪杰

Reputation: 11

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);

Upvotes: 1

Related Questions