gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 00:09:09 25 4
gpt4 key购买 nike

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

Working with QCustomPlot

最佳答案

如果你想创建如下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 设置 float 字的数量,如果将其设置为零可能会显示绘图轴中的所有数字。
setNumberFormat("g") 也可能会显示所有数字,无论如何 qCustomplot 会尽可能地在轴旁边显示值。



这是预览。

enter image description here

关于c++ - 在 QLabel 上将 12digit double 或 int 显示为 full 而不是 3.23223e+9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44999495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com