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

标签 c++ linux qt

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

相关文章:

qt - 如何缩短 Qt 制作过程?

qt - 如何使用样式表更改 QPushButton 图标/文本间距?

Android Studio 在 Ubuntu 18.04 LTS 上不断崩溃

c++ - 为 C 数学函数调用 MSVC 内置/内在函数

c++ - 没有函数模板的实例匹配参数列表我不知道为什么

c++ - 当我将 {} 分配给一个已经存在的对象时,这意味着什么?

linux - 交叉编译开源软件的专用方法

linux - lsof 命令如何获取其在 linux 上的信息

c++ - Qt/QRegularExpression - 无法捕获所有结果,只能捕获第一个实例,为什么?

c++ - 分析崩溃