+ Reply to Thread
Results 1 to 4 of 4

Thread: force repaint

  1. #1
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default force repaint

    I have reimplemented paintEvent for a number of my custom widgets

    In a couple of places, I am having the problem that I need a repaint, even though the widget itself has not changed....this is because my paintEvent can depend upon settings which I have implemented elsewhere....(e.g. the user can choose one of a few radiobuttons which describe which colour they would like certain things to be, this radiobutton emits a signal which connects to a slot in the widget in question and this slot calls update()

    I am definitely calling repaint()/update() (I have tried both) in the right places(AFIK)....but I think Qt must be optimizing and realizing that the widget itself has not in fact changed and thus does not call the paintEvent... it does not realise that the repaint depends on some third party info....and therefore does not update the colour until I change the value of the widget itself...

    Is this expected behaviour? or have I missed a logical step in my signals and slots??

    simplified code
    Qt Code:
    1. QGroupBox* gb = new QGroupBox("Group Box");
    2. QVBoxLayout* layout = new QVBoxLayout();
    3. QRadioButton *radio1 = new QRadioButton("Red");
    4. QRadioButton *radio2 = new QRadioButton("Green");
    5. QRadioButton *radio3 = new QRadioButton("Blue");
    6.  
    7. layout->addWidget(radio1);
    8. layout->addWidget(radio2);
    9. layout->addWidget(radio3);
    10. gb->setLayout(layout);
    11.  
    12. CustomWidget* cw = new CustomWidget();
    13. connect(radio1, SIGNAL(clicked()), cw, SLOT(updateColour());
    14. connect(radio2, SIGNAL(clicked()), cw, SLOT(updateColour());
    15. connect(radio3, SIGNAL(clicked()), cw, SLOT(updateColour());
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void CustomWidget::updateColour()
    2. {
    3. repaint(); //or update(); - I've tried both
    4. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void CustomWidget::paintEvent(QPaintEvent* event)
    2. { //notice that no members in the widget changed at all
    3. if(blue was clicked)
    4. change the palette to blue and call BaseClass::repaint();
    5. else if(red was clicked)
    6. as abve....usw....
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: force repaint

    From Qt docs:

    void QWidget::repaint () [slot]

    Repaints the widget directly by calling paintEvent() immediately, unless updates are disabled or the widget is hidden.

    We suggest only using repaint() if you need an immediate repaint, for example during animation. In almost all circumstances update() is better, as it permits Qt to optimize for speed and minimize flicker.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,330
    Thanks
    3
    Thanked 5,004 Times in 4,783 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: force repaint

    If more than one paintEvents are pending in the event queue, they will be merged into one event which covers a region which is a sum of all regions requested for updating. But if the widget is visible, the paint event will take place, even if no members of the class are changed. I suggest you check if the updateColour() slot is being executed at all (for example by placing a qDebug() call in it).

  4. The following user says thank you to wysota for this useful post:

    georgie (22nd May 2006)

  5. #4
    Join Date
    May 2006
    Location
    Australia
    Posts
    53
    Thanks
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: force repaint

    thanks for such fast replies!!


    yeah....I'm getting the picture that the problem is with my SIGNAL/SLOT logic, not some rare time saver thing of Qt....=) (should be simpler to fix...i'll just wait till the morning when my brain is less fuzzy)

    I will continue to look...I just wanted to check that I wasn't missing something in my understanding of the repaint() implementation

    thankyou

+ Reply to Thread

Similar Threads

  1. QPushButton not calling repaint when needed?
    By Enygma in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2010, 17:03
  2. Using QGraphicsView as a Splash Screen (repaint issues)
    By chezifresh in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2008, 21:22
  3. Replies: 3
    Last Post: 14th September 2007, 12:35
  4. nmake problems while building mysql driver
    By MarkoSan in forum Installation and Deployment
    Replies: 27
    Last Post: 25th May 2007, 12:57
  5. QT4 beginner Fatal Error
    By Remyfr in forum Installation and Deployment
    Replies: 3
    Last Post: 11th March 2006, 01:48

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