将std :: string转换为QwtText

时间:2012-09-18 11:24:18

标签: stdstring qwt

有办法做到这一点吗?我正在尝试创建一个标签,以对应我使用QwtPlotMarker创建的标记。我的目标是在下面的示例中显示一个包含我的click,m_xPos和m_yPos坐标的标签,其中包含我到目前为止的代码:

QwtPlotMarker *testMarker = new QwtPlotMarker();
testMarker->setLineStyle(QwtPlotMarker::HLine);
testMarker->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom);
testMarker->setLinePen(QPen(QColor(200,150,0), 0, Qt::DashDotLine));
testMarker->setSymbol( QwtSymbol(QwtSymbol::Diamond, QColor(Qt::yellow), QColor(Qt::green), QSize(7,7)));
testMarker->setXValue(m_xPos);
testMarker->setYValue(m_yPos);
testMarker->show();
testMarker->attach(d_graph->plotWidget());
testMarker->setLabel(....)

m_xPos和m_yPos是std :: string

2 个答案:

答案 0 :(得分:0)

QwtPlotMarker *testMarker = new QwtPlotMarker();
testMarker->setLineStyle(QwtPlotMarker::HLine);
testMarker->setLabelAlignment(Qt::AlignRight | Qt::AlignBottom);
testMarker->setLinePen(QPen(QColor(200,150,0), 0, Qt::DashDotLine));
testMarker->setSymbol( QwtSymbol(QwtSymbol::Diamond, QColor(Qt::yellow), QColor(Qt::green), QSize(7,7)));
testMarker->setXValue(m_xPos);
testMarker->setYValue(m_yPos);
testMarker->show();
testMarker->attach(d_graph->plotWidget());

QwtText markerLabel = QString::fromStdString(+ m_xPos + ", " + m_yPos +);
testMarker->setLabel(markerLabel);

是我需要做的。我已经想通了,谢谢。我没见过带QString的构造函数;我用它来连接字符串,转换为QString,然后我就能在一个情节中显示它。

答案 1 :(得分:0)

QwtText个对象可以用QString个对象构造,可以用C字符串构造。因此,以下内容应该有效:

std::string my_string("Hello, World!");
QwtText markerLabel(my_string.c_str());