【问题标题】:Draw Text on QCustomPlot在 QCustomPlot 上绘制文本
【发布时间】:2013-12-07 17:15:31
【问题描述】:

我在QCustomPlot 小部件上绘制文本时遇到问题。 A 在我的小部件中有几个图表,每个图表都在其名称中包含有关振幅的信息。 A 想在用户单击光标位置的图形时显示该文本。我有这段代码,但它不起作用,虽然当我启用 MessageBox 时,值显示良好:

QCustomPlot *nahlad; //graph
connect(nahlad,    SIGNAL(plottableClick(QCPAbstractPlottable*,QMouseEvent*)), 
   this, SLOT(kliknutieNaGraf(QCPAbstractPlottable*,QMouseEvent*)));
...   

void resultWindow::kliknutieNaGraf(QCPAbstractPlottable *a, QMouseEvent *b) 
{
    QPainter *paint = new QPainter(); paint->drawText( QPoint(b->x(),b->y()), 
        QString("Amplituda je: %1").arg(a->name()) );
    //QMessageBox::about(NULL, QString("Info"), QString("%1").arg(a->name()));
}

【问题讨论】:

    标签: qt qpainter drawtext qcustomplot


    【解决方案1】:

    如果我正确理解您的代码,您似乎直接使用 QPainter 绘制文本但没有效果(QPainter 需要 somewhere 来绘制)。

    为什么不使用内置的QCPItemText?使用方法有nice tutorial

    如果您需要进一步的解释或一段代码,请告诉我。

    S pozdravom,帕维尔

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-07
      相关资源
      最近更新 更多