在 QLabel 上将 12digit double 或 int 显示为 full 而不是 3.23223e+9

Display 12digit double or int as full instead of 3.23223e+9 on QLabel

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

我猜你想要 std::setprecision

如果你想创建如下所示 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 会尽可能地在轴旁边显示值。



这是预览。

以您想要的格式显示坐标

ui->label_xcoord_2->setNum(x2);
ui->label_ycoord_2->setNum(y2);

对QLabel使用void setText(const QString &)方法并传递

QString QString::number(double n, char format = 'g', int precision = 6)

作为具有您想要的格式和精度的参数:

Format Meaning

e format as [-]9.9e[+|-]999

E format as [-]9.9E[+|-]999

f format as [-]9.9

g use e or f format, whichever is the most concise

G use E or f format, whichever is the most concise