Results 1 to 3 of 3

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

  1. #1
    Join Date
    Jan 2008
    Location
    Warsaw, Poland
    Posts
    26
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Widget window doesn't repaint after changing its width from 0 to previous value

    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:
    Qt Code:
    1. void KeyStrokes::resizeMe()
    2. {
    3. QRect r(0, 0, calcWidth(), calcHeight());
    4. if (!r.width())
    5. QWidget::hide();
    6. else {
    7. QWidget::setGeometry(r);
    8. QWidget::show();
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    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
    If you use Qt Creator, then don't hesitate to test my Dark theme for Qt Creator.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Widget window doesn't repaint after changing its width from 0 to previous value

    I'm not sure that i understand your problem, but QWidget::repaint() repaints the widget immediately, so you might want to call that to force the repaint when you want it.

  3. #3
    Join Date
    Jan 2008
    Location
    Warsaw, Poland
    Posts
    26
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    2

    Default Re: Widget window doesn't repaint after changing its width from 0 to previous value

    Quote Originally Posted by Zlatomir View Post
    I'm not sure that i understand your problem, but QWidget::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.
    If you use Qt Creator, then don't hesitate to test my Dark theme for Qt Creator.

Similar Threads

  1. QGraphicsView doesn't repaint itself - Help!
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 18th June 2008, 14:08
  2. Replies: 3
    Last Post: 20th November 2007, 07:03
  3. Replies: 3
    Last Post: 17th October 2007, 12:52
  4. changing column width of QTableWidget
    By juliarg in forum Newbie
    Replies: 4
    Last Post: 22nd March 2007, 15:51
  5. changing the size of the tab width: QTabWidget
    By nikita in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2006, 08:31

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.