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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:11:27+00:00 2026-06-12T01:11:27+00:00

I have designed a program which, basically, cuts a geometrical shape into many small

  • 0

I have designed a program which, basically, cuts a geometrical shape into many small triangles (in a “left canvas”), applies some simple mathematical transformation to the bunch of triangles, and redraws them in their new configuration. See screen capture below.

screen cap 1

In order to draw these triangles, I use QPainter::drawPolygon. Each triangle on the right corresponds to a triangle on the left, so I know what color I want to use to draw it.

So far, fine. Even if I draw many more triangles than this (when I use much smaller triangles to cut the shape), this is fast enough.

I’ve added a feature to my program: I can draw triangles extracted from a picture instead of plain triangles: see following screen capture.

enter image description here

The problem is that the way I do this is too slow. Here’s how I do it:

  1. I run through all the triangles
  2. For each triangle, I compute the coordinates of each pixel that will be displayed.
  3. For each one of these pixels, I compute the coordinates of the corresponding pixel on the picture (this is an easy mathematical operation), and I retrieve that pixel’s color.
  4. I use QPainter::setPen(QColor) and QPainter::drawPoint(QPoint) to draw the pixel.

I am new to programming in Qt and I know nothing about graphics, so this is what I could come up with. The problem is that it’s “unacceptably” too slow (the paintEvent of each canvas takes about 0.15s, compared to 0.01s in the case of plain triangles).

I ran a profiler to try to understand what’s going on, I noticed that in the canvas widget’s paintEvent,

  1. 58% of the time is spent in QPainter::drawPoint
  2. 27% of the time is spent in QPainter::setPen

It seems that QPainter::drawPoint is far too complicated and slow: I just want it to print a pixel of a given color, that’s it.

I may have found a solution to my problem: store a QImage (as a member variable of my canvas widget) that represents the whole thing I want my canvas to display, and define it entirely in my paintEvent pixel by pixel, and then draw it at once at the end of my paintEvent with QPainter::drawImage. I have a hint that this will be much faster. But before I rewrite my code all over again, I’d like to know whether that’s really what I want to do.

I hope I didn’t bore you to do death! Many thanks in advance for your insights.

  • 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-12T01:11:28+00:00Added an answer on June 12, 2026 at 1:11 am

    Non-OpenGl solution :

    Use a RGB buffer for the destination image. Work through your 3 first steps as you did before.
    Once you have found the position and the pixel color, you set it on this buffer. Then you use

    QImage::QImage ( uchar * data, int width, int height, Format format )
    

    to construct the image based on the previous buffer. It is close to the solution you provided
    and will be much faster than what you currently have.

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

Sidebar

Related Questions

I have designed this gui in netBeans which has a canvas , a couple
I have a simple test program which is designed to consume the Apache Felix
I have a program (that I did not write) which is not designed to
I have a Windows program which generates forms. It takes the Top/Left properties at
I have a small program that which is confusing me. I am trying using
I have rewritten an old program and designed a new database for it. I
I have my little designer tool (my program). On the left side I have
I have designed a MIPS I simulator using Verilator which allows me to wrap
I have a small C program to calculate hashes (for hash tables). The code
I have created a notes field designed to hold multiple paragraphs of text which

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.