Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, January 2008
(Qt 4.3.2) Does QWidget::setGeometry() cause a QWidget::update()?


Message 1 in thread

Good morning,

As my first posting I thought I'd start with an easy one.

I have subclassed a QAbstractScrollArea, and I paint directly on its 
viewport in the paintEvent() method. I have implemented my own 
scrollContentsBy() to optimise repainting of the viewport, and by 
drawing the QPaintEvent::region() on screen I know this is all working 
as expected, and it's working very nicely.

My only problem occurs when resizing the scroll area itself (even when 
the scroll area is a top level widget). Ideally I only want the newly 
exposed parts of the viewport to be updated, so I set WA_StaticContents 
to be true on both the viewport and the scroll area. Unfortunately, this 
doesn't seem to work, and instead the entire viewport is updated. Going 
through the code for QAbstractScrollArea, the only thing I can find that 
might be the culprit is in the layoutChildren() method, where the 
viewport is resized with a call to QWidget::setGeometry(). Does this 
always cause a full QWidget::update()?

If this is causing the full repaint, why isn't it adhering to the 
WA_StaticContents attribute?

If this isn't causing the repaint, is there something else I may be 
missing that is?

Any help would be much appreciated.

Yours,
Dave

--
 [ signature omitted ] 

Message 2 in thread

David Thorne wrote:
> If this is causing the full repaint, why isn't it adhering to the
> WA_StaticContents attribute?

Hi, David. Since 4.1, as long as propagation is enabled (i.e., as long as
the widget has a background), static contents resizing doesn't work
unfortunately. It's something we'd like to improve/reintroduce in the 4.x
series but unfortunately right now the best you can do to get this behavior
is to implement your own pixmap caching, and reblit and reexpose on resize.

-- 
 [ signature omitted ] 

Message 3 in thread

Andreas, thanks for the response. I do have one question though.
> Since 4.1, as long as propagation is enabled (i.e., as long as
> the widget has a background), static contents resizing doesn't work
> unfortunately.
Your response implies that with a particular combination of propagation 
and background settings the static contents resizing would work. Is that 
the case? When I make the viewport a top level widget, static contents 
works fine, and I must profess that I don't understand the interplay 
between the conflicting / complementary attributes that affect such 
things...
    Qt::WA_StaticContents,
    Qt::WA_OpaquePaintEvent,
    QWidget::setAutoFillBackground(...),
    QWidget::setBackgroundRole(...).

If it helps answer the question, the viewport itself is solely used as a 
canvas on which I paint information. It has no child widgets of its own, 
no controls, just pretty colours ;)
> It's something we'd like to improve/reintroduce in the 4.x
> series but unfortunately right now the best you can do to get this behavior
> is to implement your own pixmap caching, and reblit and reexpose on resize.
>   
As it happens I had to implement pixmap caching anyway otherwise 
scrolling the widget would have also crawled to a halt (my application 
has to render a window full of coloured and tessellated rectangles, and 
when those rectangles are zoomed out to 2x2 pixels and I have my window 
maximised on my 30" display, that's a lot of real estate to have to 
repaint interactively).

Yours,
Dave

--
 [ signature omitted ] 

Message 4 in thread

David Thorne wrote:
> Andreas, thanks for the response. I do have one question though.
>> Since 4.1, as long as propagation is enabled (i.e., as long as
>> the widget has a background), static contents resizing doesn't work
>> unfortunately.
> Your response implies that with a particular combination of propagation 
> and background settings the static contents resizing would work. Is that 
> the case?

No. Static contents does not work for child widgets, only for top-level 
widgets. But as Andreas said, this is something we will look into fixing 
for some future release.

-- 
 [ signature omitted ]