简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM