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

  • Home
  • SEARCH
  • 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 7753999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:11:48+00:00 2026-06-01T12:11:48+00:00

I have a custom Widget derived from QFrame. I will need to draw on

  • 0

I have a custom Widget derived from QFrame. I will need to draw on it very frequently (basically, a picture is updated with every mouse move). I checked the Qt Basic drawing example: They override paintEvent, create a painter and do their drawing (and the painter dies at the end of its lifetime, facing the final cur…ly bracket).

For my small testing app, performance is no issue, but I would like to better understand painting operations (or rather: the cost of instantiating temporary objects in a frequently called method), so I was wondering: If the custom QFrame held a pointer to a (permanent) painter and uses it for painting, would that be preferable over creating and deleting one with every call of paintEvent?

Thanks for your time,
Louise

  • 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-01T12:11:49+00:00Added an answer on June 1, 2026 at 12:11 pm

    Simply put: don’t worry about it.

    Qt does some magic behind the scenes to make the creation of a QPainter fast – notably, the “heavy” part of the state (the paint engine) is shared by all QPainters that operate on the same paint device. (See here.)

    Now if you call a bunch of functions that need a painter from your paintEvent handler, pass them reference to the QPainter – no need to create one for each separate call.
    But generally, don’t worry about it. Use the same idioms as you see in the examples, and only try and do “smarter” stuff if you actually measure that instantiating QPainters is a bottleneck in your code.

    (This isn’t limited to QPainter – Qt does a lot of “behind the scenes” sharing, copy-on-write type manipulations for heavy objects. The examples and tutorials show how you’re supposed to use the API (and they are generally pretty high quality). Follow the examples and only try to outsmart them if you have specific reasons/use cases where more intricate management is required.)

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

Sidebar

Related Questions

I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
In my project I am using a custom circle-shaped button widget derived from the
Basically I have written a custom widget, which is going to be displayed 5
Say I have a custom GTK+ widget obtained from a third party library. It
I have a custom adapter for ListView and I need to return LinearLayout from
i am developing a Gtk# based application which uses a custom widget derived from
Suppose I have a MyWidget which contains a MySubWidget , e.g. a custom widget
I have developed a custom dijit Templated Widget. I have to do some DOM
i have created a custom post type named Books & i have a widget
i have an custom widget in dojo. My Problem is to check some kind

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.