如何让股票在qgraphicsrectitem Qt中 我尝试以下如何在qgraphicsrectitem股票在Qt的
rect = new QGraphicsRectItem;
text = new QGraphicsTextItem;
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
rect = scene->addRect(0,0,500,500);
text->setPlainText("HELLO from constructor");
scene->addItem(text);
QFont font;
fm = new QFontMetrics(font);
ntextWidth = fm->width(text->toPlainText());
text->setPos(0,rect->boundingRect().height()/2);
ntextHeight = fm->height();
QString strtxt = fm->elidedText(text->toPlainText(), Qt::ElideRight, ntextWidth-50, Qt::TextShowMnemonic);
qDebug() << "Here Lenght in pixels:" << ntextWidth <<"====" <<ntextHeight <<"-----"<<strtxt.contains("…");
connect(&timer, SIGNAL(timeout()),this,SLOT(update()));
timer.start(5);
}
GraphicsTicker::~GraphicsTicker()
{
delete ui;
}
void GraphicsTicker::update()
{
text->setPos(text->x()+1,text->y());
if(text->x()==rect->boundingRect().width()-ntextWidth)
{
ntextWidth = ntextWidth-1;
strNewText = fm->elidedText(text->toPlainText(),Qt::ElideRight,ntextWidth).remove("…");
text->setPlainText(strNewText);
}
if(text->x() == rect->boundingRect().width()-20)
{
text->setPlainText("HELLO from constructor");
ntextWidth = fm->width(text->toPlainText());
text->setPos(0,text->y());
}
我已经使用qgraphicstextitem和qgraphicsrectitem这一点。 我移动文本取决于使用定时器的矩形的位置。 但它不是完美的,因为新浪体育讯北京时间 请给我聪明的解决方案
由于提前