Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8315317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:06:20+00:00 2026-06-08T21:06:20+00:00

I am wondering in which cases does a widget receive its paint event, and

  • 0

I am wondering in which cases does a widget receive its paint event, and how does it vary with the OS.

Qt documentation for paintEvent says only

A paint event is a request to repaint all or part of a widget. It can happen for one of the following reasons:

repaint() or update() was invoked,

the widget was obscured and has now been uncovered, or

many other reasons.

So far, I’ve put some traces in the paintEvent,

void Widget::paintEvent(QPaintEvent *e)
{
    static int count = 0;
    qDebug("paintEvent, %d", count++);
}

and this is what I’ve found out (on Windows 7 at least):

The paintEvent is called when the widget loses/gains focus. The paint event is not called when another widget passes over our widget. I don’t know if that’s because of Windows 7 compositing. The paintEvent is also called when a minimized window is restored. The paintEvent is called when resizing.

So is the behaviour dependent on the OS?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:06:21+00:00Added an answer on June 8, 2026 at 9:06 pm

    Yes, in the sense that you describe, it’s dependent upon the operating system.

    The Desktop Window Manager (DWM), found in Windows Vista and 7, the doohickey that is responsible for desktop composition, the Aero glass effect, and all kinds of other eye candy, works a bit differently than the model used in previous versions of Windows. As you suspect, it caches the bitmaps for your windows, even when they are not visible because they’re obscured by another window. That means it doesn’t need you to repaint them (and thus it doesn’t raise a paint event) because it can just blit them from the cached bitmap. Not only is this a potential optimization over having each application redraw itself, it also allows the DWM to implement things like Aero Flip, for which it uses its cached bitmap.

    The exception to this is as it has always been for, say, the CS_SAVEBITS class style. If the bitmap that the DWM has cached has become invalidated (e.g., because your window image has changed), it will discard it and ask you to redraw the window.

    Test this theory by turning off DWM composition (switching to the “Windows Classic” theme), and then obscuring your window to see if you receive a paint event. You should, just like you did in all previous versions of Windows.

    But the larger point is that you should not rely on receiving paint events in any particular order. The only thing you should assume about paint events is that you’ll receive one when the operating system needs you to repaint your window. Otherwise, it won’t bother you. I’m sure that’s why the documentation is content with being vague on this point, beyond possible technical constraints.

    This is why logic should not go inside of the paint event handler. The only thing that method should be responsible for is repainting the window by its current state. That state needs to saved elsewhere. This rule is also commutative: you should not do any painting outside of the paint event handler.

    Of course, you can always force a paint event to be raised by invalidating your window (I’m sure Qt has an invalidate or refresh method for this, check the documentation), but that still doesn’t mean it’s a good pattern to place application logic in the method that handles this event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering in which cases one should put the values of an animation
I was wondering which way is better to work with. Using private attributes at
I was wondering which could be a better way of mounting different apps for
I am wondering which is more efficient, to store temporary data (related to that
I was wondering which kind of expressiveness fits a language used to generate particle
I was wondering which DVCS is most conducive to experimentation i.e. branching, etc. I
I am wondering which way would end up being faster, selecting elements by: $('element[href=#my_link]');
I was wondering which tool in ORACLE 11g (their latest DBMS) can be used
I was wondering which of these two scenario's works best for swapping between 2
I was just wondering which would be cheaper, using a try catch block for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.