【问题标题】:Display 12digit double or int as full instead of 3.23223e+9 on QLabel在 QLabel 上将 12digit double 或 int 显示为完整而不是 3.23223e+9
【发布时间】:2017-07-09 18:07:33
【问题描述】:

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

【问题讨论】:

标签: c++ qt numbers qcustomplot


【解决方案1】:

如果您想像下面的代码一样创建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 尝试在轴旁边显示值,因为它可以是美丽的。



这是一个预览。

【讨论】:

    【解决方案2】:

    我猜你想要std::setprecision

    【讨论】:

    • 感谢您的即时回复,检查了文档,它仅供流媒体使用。如果我想这样设置怎么办 ---- ui-&gt;label_xcoord_1-&gt;setNum(x3); 试过了 ---- ui-&gt;label_xcoord_1-&gt;setNum(std::setprecision(12)&lt;&lt;x3) 但没用
    【解决方案3】:

    以您想要的格式显示坐标

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

    对 QLabel 使用void setText(const QString &amp;) 方法并通过

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

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

    格式含义

    e 格式为 [-]9.9e[+|-]999

    E 格式为 [-]9.9E[+|-]999

    f 格式为 [-]9.9

    g 使用 e 或 f 格式,以最简洁的为准

    G 使用 E 或 f 格式,以最简洁的为准

    【讨论】:

    • 非常感谢,解决了我的整个问题。你拯救了我的一天。
    猜你喜欢
    • 1970-01-01
    • 2014-05-26
    • 2020-02-03
    • 2013-07-10
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 2012-10-23
    相关资源
    最近更新 更多