2014-09-01 94 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添加到窗口小部件中,並設置其開始和結束值,使其看起來像一個報時器正在移動,從而製作報價器。對於標籤的這種「幾何」考慮移動