I have a QTextEdit object that I use to display text, line by line, for OSD purposes. I would like to be able to change the position of this text box around the window without using a mouse.
The issue is that when I "move" the QTextEdit text box, all of the previous text boxs continue to exist alongside the new one.
I have been using setGeometry(x,y,w,h) to configure the position and size of the text box when I create it. I have also experimented with resize(w,h) and move(x,y), which seem to work similarly to setGeometry(). If all I want to do is to show some text, is QTextEdit the right part or is there something better? I am using Qt 4.8.
class MainWindow : public QMainWindow
explicit MainWindow(QWidget *parent = 0);
QTextEdit *osd; // Make osd a member
// These globals are set in a separate thread
// that takes user input to resize the QTextEdit box geometry.
MainWindow::MainWindow(QWidget *parent) :
// Create a new QTextEdit text box
osd = new QTextEdit(this);
// Set a Qtimer to update the OSD display every 1 second
QTimer *timer = new QTimer();
connect(timer, SIGNAL(timeout()), SLOT(val_changed()));
g_val_update = false;
// Update the OSD
// Clear the old data from the OSD
// Set the geometry based on user input
osd->setGeometry(g_xpos, g_ypos, g_w, g_h);
QString arg = QString("OSD position %1 %2).arg(g_xpos).arg(g_ypos);
QString arg = QString("OSD size %1 %2).arg(g_w).arg(g_h);
How can I change the geometry of a QTextEdit object without having previous versions also rendered?
setGeometry is fine , but you should call
QTextEdit::clear() to clear the previous data displayed in your
QTextEdit before writing a new text.
If all I want to do is to show some text
Then you might also find interesting to have a look at