如何在 Qt 中的 qgraphicsrectitem 中制作自动收报机 我试着跟随
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。 我移动文本取决于 rect 使用计时器的位置。 但它不如 Ticker 完美 请给我聪明的解决方案
提前致谢
最佳答案
我已经在 Qt 中完成了自动收报机。 我简单地使用了 Qlable 并使用它旋转了它上面的文本,然后我使用 Qgraphicsproxywidget 在 Qgraphicsscene 中添加了这个标签。 谢谢你们。
关于c++ - 如何在 Qt 的 qgraphicsrectitem 中制作自动收报机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25605345/