How to reset text on QCustom3DLabel?

Viewed 161

On the following I'm trying to change text of QCustom3DLabel but it doesn't change. So, any suggestion on how to deal with this?

MainWidget::MainWidget(QWidget *parent) : QWidget(parent)
{
    resize(800,600);
    auto vLayout = new QVBoxLayout(this);

    auto graph = new Q3DBars;
    vLayout->addWidget(QWidget::createWindowContainer(graph));

    auto camera = graph->scene()->activeCamera();
    camera->setCameraPreset(Q3DCamera::CameraPresetIsometricLeft);

    graph->axes()[0]->setRange(0,5);
    graph->axes()[1]->setRange(0,5);
    graph->axes()[2]->setRange(0,5);

    label = new QCustom3DLabel;
    label->setText("123");
    label->setScaling({5,5,5});
    label->setPosition({1,1,1});
    graph->addCustomItem(label);

    auto timer = new QTimer;
    connect(timer, &QTimer::timeout, this, &MainWidget::setText);
    timer->start(2000);
}

void MainWidget::setText()
{
    qDebug() << "settext";
    label->setText("1234567890");
}
1 Answers

I reproduced the code and problem was same for changing other properties too(for example background color didn't change either).

anyway, here i wrote a not very clean code that works for changing label text:

void MainWidget::setText()
{
   graph->releaseCustomItem(label);
   QCustom3DLabel* newlabel = new QCustom3DLabel(nullptr);
   newlabel->setScaling(label->scaling());
   newlabel->setPosition(label->position());
   newlabel->setText("1234567890");
   label = newlabel;
   graph->addCustomItem(label);
}

I don't know why, But setText alone could change value of text property , but had no graphical effect.

However, When i created a new instance of QCustom3DLabel and called setText for that, it worked fine. I just had to release the previous label from graph.

Related