PDA

View Full Version : Widget window doesn't repaint after changing its width from 0 to previous value



przemoc
29th June 2010, 00:44
I have a frameless window widget staying on top and bypassing window managment (Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint). It has reimplemented paintEvent() and it is often resized. Resizing is done from slot (QSocketNotifier::activated(int) signal is connected to it) by calling below resizeMe() method:


void KeyStrokes::resizeMe()
{
QRect r(0, 0, calcWidth(), calcHeight());
if (!r.width())
QWidget::hide();
else {
QWidget::setGeometry(r);
QWidget::show();
}
}

It works fine, but if I move setGeometry() outside of the conditional block (and convert hide()/show() into setVisible() to completely remove if-else), then the widget's paintEvent() is not invoked after changing the width from 0 to previous value (and I get obviously empty rectangle).

Example: 0 - 10 (repaint) - 20 (repaint) 0 - 15 (repaint) - 0 - 15 (NO repaint).

What am I missing here? Isn't it a bug in Qt?

Linux version 2.6.33.4, Debian squeeze, gcc version 4.4.4 (Debian 4.4.4-1), libqt4-* 4.6.3-1

Zlatomir
29th June 2010, 00:57
I'm not sure that i understand your problem, but QWidget::repaint() (http://doc.qt.nokia.com/latest/qwidget.html#repaint) repaints the widget immediately, so you might want to call that to force the repaint when you want it.

przemoc
29th June 2010, 01:40
I'm not sure that i understand your problem, but QWidget::repaint() (http://doc.qt.nokia.com/latest/qwidget.html#repaint) repaints the widget immediately, so you might want to call that to force the repaint when you want it.

I don't have a problem in above code, but I encountered strange behaviour when the code was simplified (as I already described it). I want to be convinced that this behaviour isn't insane or that it is just a bug.

First of all, IMO there is no need for repaint()/update() (or even: it shoudn't be needed here), because geometry is changed, so paintEvent() will be invoked anyway. But it isn't invoked if we're setting geometry as it was before we've zeroed it. That's the problem. Actually removing show()/hide()/setVisible() doesn't change the situation (it's just a matter of taste - I prefer having hidden window when its width is zero).

QWidget::repaint() does not help here.