C++在QLabel上显示一个数字3232235975作为3.23223e+9,而在QCustomPlot轴上显示为3.23223*10^9。我没有涉及像std::cout这样的流,这就是为什么std::setprecision不适合我的情况。
我实际上与QCustomPlot一起绘制轴上有12位数字的图形。这是C++问题还是QCustomPlot机制问题?如何显示数字的所有数字?
谢谢
编辑:在收到来自@saeed的setNumberPrecision()提示后,协调仍然以2.88798e+9格式显示。现在轴已经显示了4000000000,我希望协调QLabel (显示在我所附的图像中)也显示2887984335。
我得到了协调,并将其设置为这样的QLabel。
double x2 = ui->widget_graph2->xAxis->pixelToCoord(_mouseEvent->pos().x());
double y2 = ui->widget_graph2->yAxis-pixelToCoord(_mouseEvent->pos().y());
ui->label_xcoord_2->setNum(x2);
ui->label_ycoord_2->setNum(y2);我使用setData()设置绘图数据,如下所示
QVector<double> x2(i), y2(i);
for(int o = 0; o <= i; o++){
double dSec = arrayIPxTime[o][0] - startSecond;
double dMin = dSec/60;
double ipv4addr = arrayIPxTime[o][1];
x2[o] = dMin;
y2[o] = ipv4addr;
}
ui->widget_graph2->addGraph(0);
ui->widget_graph2->graph(0)->setData(x2, y2);
ui->widget_graph2->installEventFilter(this);

发布于 2017-07-10 14:17:34
以所需格式显示坐标
ui->label_xcoord_2->setNum(x2);
ui->label_ycoord_2->setNum(y2);用void setText(const QString &)方法实现QLabel和pass
QString QString::number(double n, char format = 'g', int precision = 6)作为你想要的格式和精度的参数:
格式意义 E格式为-9.9e+x-999 E格式为-9.9E+x-999 F格式as -9.9 使用e或f格式,以最简洁的形式为准。 使用E或f格式,以最简洁的形式为准
发布于 2017-07-10 05:05:15
如果您想像qCustomPlot样例一样创建下面的代码,请设置轴属性,如下面的代码。
// setup look of bottom tick labels:
customPlot->xAxis->setTickLabelRotation(30);
customPlot->xAxis->ticker()->setTickCount(9);
customPlot->xAxis->setNumberFormat("ebc");
customPlot->xAxis->setNumberPrecision(1);
customPlot->xAxis->moveRange(-10);
// make top right axes clones of bottom left axes. Looks prettier:
customPlot->axisRect()->setupFullAxesBox();setNumberPrecision设置浮点数,如果将其设置为零,则可以显示绘图轴中的所有数字。
setNumberFormat("g")也可以显示所有的数字,无论如何,qCustomplot试图在轴旁边显示值,就像美丽一样。
这是一个预览。

发布于 2017-07-09 18:10:07
我猜你想要std:设定精度。
https://stackoverflow.com/questions/44999495
复制相似问题