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 6325037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:49:14+00:00 2026-05-24T16:49:14+00:00

I have a main window with some widgets on it, each needs its own

  • 0

I have a main window with some widgets on it, each needs its own graphic. I would like to use QPainter to draw shapes, lines, etc. on them, but only after a specific event, like the press of a button.

The problem is, if I just create a QPainter in any function, it won’t work:

QPainter::setPen: Painter not active

The QPainter methods can only be called inside a paintEvent(QPaintEvent *) function! This raises the following problems:

  1. I have to derive my custom classes for all the widgets I would like to paint on, so I can’t use the Designer to place my widgets. This can get frustrating with a large number of widgets.

  2. The widgets redraw themselves after each paint event of the window, like moving it around, or moving other windows in front of it. I do a lot of drawing in those widgets, so they will visibly blink in these cases.

Is there a better and simpler way to solve this? I started to think about just displaying images, and re-manufacturing those images only when the specific buttons are pressed. I doubt that it’s the most elegant solution…

  • 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-05-24T16:49:14+00:00Added an answer on May 24, 2026 at 4:49 pm

    You can use custom widgets in the designer: Creating Custom Widgets for Qt Designer.

    Qt Designer’s plugin-based architecture allows user-defined and third party custom widgets to be edited just like you do with standard Qt widgets.

    For your second question, one of the approaches is to create a QPixmap for each of your widgets. When your widget’s appearance needs to be changed, you draw in that pixmap (using QPainter‘s constructor that takes a QPaintDevice – QPixmap is a QPaintDevice).

    In your widget’s paintEvent function, you simply fill your widget with that “cache” pixmap. This way, you only do the (potentially expensive) painting when it’s actually necessary.

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

Sidebar

Related Questions

I have my main program window, and I would like to make a foldable
I have an Air application with a main window. I would like to have
I have main window from type QMainWindow , then I set some widget and
Looking for some guidance. In my main window nib file, i have a tab
I have my main window and I'd like to attach a sheet to it:
I have a Main app window (JFrame) with JPanel. On JPanel I have some
i have some simple hierarchy of widgets looks something like this : MainWindow->setObjectName(QString::fromUtf8(MainWindow)); MainWindow->resize(423,
I have code that keeps my main window in its respective aspect ratio when
I have created a small window with some style. Now i want to use
I have a main window (#1) on my webpage from which I open a

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.