2014-09-01 91 views
1

如何让股票在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这一点。 我移动文本取决于使用定时器的矩形的位置。 但它不是完美的,因为新浪体育讯北京时间 请给我聪明的解决方案

由于提前

回答

0

我曾与股票Qt中完成的。 我简单地使用了Qlable,并使用这个我旋转的文本,然后我用Qgraphicsproxywidget在Qgraphicsscene中添加了这个标签。 谢谢大家。

0

您可以使用Qpropertyanimation通过简单地将Qlable添加到窗口小部件中,并设置其开始和结束值,使其看起来像一个报时器正在移动,从而制作报价器。对于标签的这种“几何”考虑移动