PDA

View Full Version : Newbie -- repaint() not repainting window



a7scenario
23rd March 2015, 15:09
I'm not sure if this is a bug in Qt 5.4.1 or I'm doing something wrong. Here is my stripped down code that is failing to repaint the window EXCEPT when I call resize() after a repaint(). If you run the code below, it'll properly repaint the window. If you remove the last call to resize() at the bottom, it will NOT repaint the window. Any help is appreciated. Thanks.

QPlainTextEdit mytextbox;

mytextbox.resize(500,500);
mytextbox.insertPlainText("first string");
mytextbox.show();
mytextbox.insertPlainText("DID IT CHANGE??");
sleep(1);
mytextbox.repaint();
mytextbox.resize(500,501); :confused:

jefftee
23rd March 2015, 15:23
Where are you executing this code? Since you are not returning to the event loop between calls to insertPlainText, I'm not surprised that you are forced to manually repaint or resize (which also requires a paint).

What happens if you replace sleep(1) with processEvents()?

iswaryasenthilkumar
24th March 2015, 11:34
try this line in your program
activateWindow();
bt am not this was correct its just my suggestion

I'm not sure if this is a bug in Qt 5.4.1 or I'm doing something wrong. Here is my stripped down code that is failing to repaint the window EXCEPT when I call resize() after a repaint(). If you run the code below, it'll properly repaint the window. If you remove the last call to resize() at the bottom, it will NOT repaint the window. Any help is appreciated. Thanks.

QPlainTextEdit mytextbox;

mytextbox.resize(500,500);
mytextbox.insertPlainText("first string");
mytextbox.show();
mytextbox.insertPlainText("DID IT CHANGE??");
sleep(1);
mytextbox.repaint();
mytextbox.resize(500,501); :confused: