View Full Version : Problem with QScrollArea updating from 4.0.1 to 4.1.0

27th January 2006, 00:25
Hi all. I downloaded the last version of Qt (4.1.0) for Windows. I'm using windows XP. Before, I was using 4.0.1 version, so I thought that wouldn't exist problems updating my program to the new version. But I'm really worried, because the scroll area that I was using don't works and with version 4.0.1 worked perfectly. Well,this is what I do in the program: I have subclassed QScrollArea and I have reimplemented the method paintEvent to resize the widget that contains the scroll area since the size of the viewport and the size of the image that I draw on the widget. With version 4.0.1 the paintEvent method was called everytime the size of the main window changes, so the widget of the scroll area was ever updated. But my surpise comes when, with the new version, the paintEvent method is not called if I resize the main window. Very strange and annoying. Moreover if I call viewport() method in the paintEvent to know the size of the viewport, it give me invalid values. I have readed the list of changes of the new version but I havent' found anything changed in QScrollArea :confused: Could the problem come because I have subclased too the paintEvent method of the widget that contains the scrollarea? I repeat that the same code worked perfectly with the version before (4.0.1). But I have to use the new version because it has fixed some bugs that I need; for example saving jpegs in different quality factors and others. Anyone could explain me why it doesn't work now or what's the difference between the old QScrolArea and the new? Many thanks.

Chicken Blood Machine
27th January 2006, 06:04
Shouldn't you be overriding the paintEvent of the QScrollArea widget?

27th January 2006, 12:40
Do you mean if I have reimplemented the paintEvent method of the scroll area? yes because I need do it

28th January 2006, 12:46
I still need help. Has Anybody experimented the same or a similar problem with this new version or knows how to solve it? The thing is that is very frustrating to see that a thing that with version 4.0 works perfectly now with just version 4.1 doesn't :(

28th January 2006, 19:24
I understand it can be frustrating, but you're maybe using the API in a way that results in undefined behavior (works in Qt 4.0 by mere luck, doesn't work in Qt 4.1).

A minimal compilable example that reproduces the problem would help here.

28th January 2006, 22:50
Well, I comment with more details the problems that I have noticed with the scroll area of this new version (4.1.0). I have subclassed QScrollArea because I need to reimplement the method paintEvent. I put an instance of this class as a central widget of a main window. I want that the first time that appears the main window is in full screen, calling QMainWindow::setWindowState(Qt::WindowMaximized). Well, I subclass QWidget because i want to paint under the widget a image with qpainter on the paint event of the iwdget. I put this widget inside the scroll area with ScrollArea::setWidget method. And here comes the main problem: the paintEvent of the scroll area only is called the first time the scroll area is shown: if I try to resize the main window, the paint event of the scroll area is not called while in version 4.0.1 was called everytime I resized the main window. I find it very strange :confused: . For example if i put the next code in the paintEvent of the scroll area:

void FotoAreaEditorFotos::paintEvent(QPaintEvent *event)
FotoEditorFotos *foto = widget();

if (foto)
foto -> resize(viewport() -> width(), viewport() -> height());

"FotoAreaEditorFotos" is my subclass of "QScrollArea" and "FotoEditorFotos" is the widget that i insert in the scroll area. I have reimplemented the functions widget() and setWidget() of my scroll area to only permit insert and return instances of "FotoEditorFotos" class.
The rersult of this example code should resize the widget that manages the scroll area to the viewport's size everytime the paint event is called. So, in theory, if i resize the main window, the paint event method has to be called and, so, the widget of the scroll area should be resized to the new viewport's size. Well in the partice, the result of this code is that the widget is resized only the first time: when I try to reduce the size of the main window (the first time is shown at full screen), appears the scroll bars on the scroll area meaning that the widget has not been resized to new viewport's size.

I hope this time all this explanation could help to find my problem. Thanks.

Chicken Blood Machine
28th January 2006, 23:01
Why aren't you using the resize event instead of the paint event?

It looks like you are really trying to respond to resizes, so use the resize event. There is no guarantee that the paintEvent will be called unless you expose new areas of a widget (by resizing larger, or moving something that overlaps the widget), so you should not be relying on the paintEvent to track resizes.

[Of course I may be misunderstanding what you are trying to do here.]

28th January 2006, 23:07
Hi Chicken Blood Machine (great name :D ) I think that this event could help, I'm gonna try it. I didn't knew that exist this event that's why I made it in the paintEvent ... :(

28th January 2006, 23:35
It works!!!!!!!!! Simply i have changed the paintEvent for resizeEvent :D. I dont' understand why it worked in the previous version ... Thanks