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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:26:26+00:00 2026-06-15T23:26:26+00:00

I am currently trying to encapsulate my QPainter objects into reusable classes, possibly deriving

  • 0

I am currently trying to encapsulate my QPainter objects into reusable classes, possibly deriving each other. This enables them to transform the painter around any way they like, have their own children to draw etc:

I have DrawArc derived from QPainterPath

DrawArc::DrawArc() : QPainterPath()
{}

void DrawArc::paint(QPainter* painter)
{
    painter->save();
    //...
    arcTo(/*...*/);
    lineTo(/*...*/);
    painter->translate(QPoint(100,100));
    painter->drawPath(*dynamic_cast<QPainterPath*>(this));
    painter->restore();
}

and DrawBeam derived from DrawArc

DrawBeam::DrawBeam() : DrawArc()
{}

void DrawBeam::paint(QPainter* painter)
{
    painter->save();
    //...
    painter->setPen(QPen(color, 4));
    painter->setBrush(brush);
    DrawArc::paint(painter);
    painter->restore();
}

In the actual Widget I am doing the following

BeamWidget::BeamWidget(QWidget* parent) : QWidget(parent)
{
    DrawBeam* mybeam = new DrawBeam();
}

void BeamWidget::paintEvent(QPaintEvent * /* event */)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);

    mybeam->paint(&painter);
}

However I am seeing dramatic performance losses in painter->drawPath(*dynamic_cast<QPainterPath*>(this)); after a few seconds (or few hundred redraws). Everything else in the remaining procedure seems to run fine but when I enable that line the performance degrades quickly.

Also all elements deriving from DrawArc painting seem to sometimes lose their QBrush styles and remain visible even though setAutoFillBackground(true); is set…

  • 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-15T23:26:27+00:00Added an answer on June 15, 2026 at 11:26 pm

    I found out this has to do with me only creating the object once, then adding an arcTo and a few other lines to it during each run of paint(). Since I can’t flush the QPainterPath the Path simply becomes longer and longer and longer and longer.

    This explains why old lines are not being flushed and why the brush is alternating (each time I re-draw the same thing I am forming a new intersection with the path itself, wich by design is not being filled).

    I fixed it like this:

    void DrawArc::paint(QPainter* painter)
    {
        painter->save();
        //...
    
        QPainterPath path = QPainterPath(*this);
        path.arcTo(/*...*/);
        path.lineTo(/*...*/);
    
        painter->translate(QPoint(100,100));
        painter->drawPath(path);
        painter->restore();
    }
    

    So in each drawing operation I create a copy of the current path, add all lines I need to it and paint that one. After exiting paint, that drawn path is being discarded.

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

Sidebar

Related Questions

I'm trying to create classes to encapsulate validation and logic for objects like Email
I'm currently trying this: using DocumentFormat.OpenXml.Packaging; using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileNameDocx as string, true))
I'm currently trying to get the most popular productID from my MSSQL Database. This
Currently trying to get a Bluteooth sample working. I'm using this sample as reference
Im currently trying to save the tab.url into html5 local storage when the programme
I'm currently trying to implement the repositories for my domain objects with the RC
Currently trying at add ajax to a site, after much reading I discovered that
Im currently trying to downlaod a audio track from a WCF, i need some
Im currently trying to learn some stuff about encryption, it's algorithms and how it
I am currently trying to write some code that will accept some FTP details,

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.