Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to make point's text lable adjust with scale of x-axis and y-axis in QCustomPlot?



  • x[0] = 10;
    y[0] = 50;

    x_offset = 0.7;
    y_offset = 1.0;
    QCPItemText *textLabel = new QCPItemText(ui->widget);
    textLabel->position->setCoords(x[0]- x_offset, y[0] + y_offset); // place position at center/top of axis rect
    textLabel->setColor(Qt::white);
    QString str;
    str.sprintf("%d", 10);
    textLabel->setText(str);
    textLabel->setFont(QFont(font().family(), 8)); // make font a bit larger

    The problem is , if x-axis range is (-20,20), y-axis range is (-50,100), the text lable is near the point(x[0],y[0]) properly. when x-axis range is set to (-200,200), y-axis range is set to (-500,500), the lable is merge with point(x[0],y[0]) because of large scale, what I want is lable's postion is near the point from the eye of view
    how to solve this problem? for this kind of problem,MATLAB solved it perfectly, point and its lable are
    displayed rightly under different scale of x-axis and y-axis


  • Lifetime Qt Champion

    Hi
    If you don't get any answers here, try the QCustomPlot forum.
    https://www.qcustomplot.com/index.php/support/forum

    QCustomPlot is not an official Qt module so you have to be lucky that someone knows here.


Log in to reply