gpt4 book ai didi

c++ - 如何在 Qt 的 qgraphicsrectitem 中制作自动收报机

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:32:03 26 4
gpt4 key购买 nike

如何在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com