PDA

View Full Version : Neither QWidget update() nor repaint() will repaint; only resizing does



John Mcgehee
15th October 2010, 01:19
I modified the basicdrawing example to create my own program that is very similar. It merely draws text in the RenderArea widget instead of polygons, etc.

When my application starts up, paintEvent() runs and everything looks good. When I change something (like the text string), I do update(), but nothing is repainted. Same thing with repaint(). Just to make sure, I did setUpdatesEnabled(true) immediately before update(). It still does not work.

If instead I resize by moving the corner of the window with the mouse, paintEvent() runs, and everything looks just as I expected, with the updated text string painted. Currently, resizing the window is the only way I can repaint.

I am using Fedora 11 Linux with Qt 4.6.2. I see people recommending Qt 4.6.3 (http://www.qtcentre.org/threads/31486-QT-4.6.2-QGraphicsView-paintEvent()-not-able-to-be-triggered-by-update()-repaint(), but I hesitate because I compiled basicdrawing with 4.6.2, and it does update() just fine.

John Mcgehee
15th October 2010, 07:40
Fedora 12 has Qt 4.6.3, so I tried linking to 4.6.3, and it did not solve the problem.

faldzip
15th October 2010, 09:39
Can you show us what did you change exactly in this basicdrawing code? Because if it was working before changes and now it isn't so the most possible situation is that ou have done something wrong and we don't know what you have exactly done.

John Mcgehee
15th October 2010, 19:40
Thank you for your response.

The relevant code is attached. 5330

This program stores and retrieves the text in an "OA" database, which is not mine to share. A text object in this database has the same attributes as a text you draw with QPainter (origin, orientation, alignment, bounding box, etc.).

vview.jpg shows you the dialog that is created. QPainter is drawing correctly. As I said above, the problem is that I can only get it to redraw by resizing the window


I could only attach five files, so here is the interesting part of main.cpp:

#include <QApplication>

#include "window.h"

int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(basicdrawing);
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}

John Mcgehee
17th October 2010, 22:30
When I change something (like the text string), I do update(), but nothing is repainted. Same thing with repaint().

I found the problem. I unintentionally reimplemented QWidget::setVisible(). I just changed the name of my method to setTextVisible(), and now it update() works fine.