QLabel::setText() not responding properly
-
I m trying to modify the text of a QLabel object, I want to show the count in label object's text.
Following is what I tried:ui->Frame_ID->setText("1"); . . . ui->Frame_ID->setText(" "); ui->Frame_ID->setText("2");
But after the last line the text on label shows both values overlapped. ui->Frame_ID->setText(" ") did not clear the previous value. Apart from that I also tried ui->Frame_ID->clear(); but the output was same.
-
@surajj4837
QLabel::setText()
does reset the text to the new value, completely discarding the previous value, andclear()
does clear it. No idea what you mean by "shows both values overlapped". Show a screenshot, and it hardly needs saying that for a question like this you must state your platform and what version of Qt you are using. -
I m using Qt 5.13.2 in Ubuntu 20.04.
In following screenshot, top left corner shows the label I want to modify. The frame numbers are printed on each other (0, 1 and 2).
Following code sets the values in the label text:ui->Frame_ID->setText(" "); //Clear the text std::string text = "Frame No: " + std::to_string(CurrentFrame); //Frame new text ui->Frame_ID->setText(QString(text.c_str())); //Set new text
-
@surajj4837
This seems to me to be something to do with whatever background your label is on. Out of interest, what happens to the visual label if you simple hide/delete the label? -
@JonB Actually you are right, in the background I m using QVTKWidget which is causing this overlap display, when I moved that QLabel object to some other place on an empty background and also on another QLabel object, the operation is happening fine. There seems to be an uknown issue with QVTKWidget.
-
@surajj4837 said in QLabel::setText() not responding properly:
QVTKWidget
I thought so! I know nothing about "QVTKWidget". Is it old/deprecated? A random post I came across suggesting problems with widgets on it is http://vtk.1045678.n5.nabble.com/QVTKWidget-vs-QVTKOpenglWidget-vs-QVTKWidget2-td5748605.html . Are you supposed to move to some "QVTKOpenglWidget" or "QVTKWidget2"?
-
@JonB Thanks, this is new information for me. Actually the "QVTKWidget" was sufficing my problem to display point cloud data. For now it is working properly because I m using VTK 7.0. It seems post VTK 8.0, the QVTKOpenglWidget needs to be used.