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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:26:48+00:00 2026-06-12T04:26:48+00:00

I need to do something similar to QPainter::drawImage , but drawing a triangle part

  • 0

I need to do something similar to QPainter::drawImage, but drawing a triangle part of the given picture (into a triangular region of my widget) instead of working with rectangles.

Any idea how I could do that, besides painfully trying to redraw every pixel?

Thanks 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-12T04:26:49+00:00Added an answer on June 12, 2026 at 4:26 am

    If it is feasible for you to use a QPixmap instead of a QImage, you can set a bitmap mask for the QPixmap which defines which of the pixels are shown and which are transparent:

    myPixmap->setMask(myTriangleMask);
    painter->drawPixmap(myPixmap);
    

    Here is another solution based on QImage:

    MaskWidget::MaskWidget(QWidget* parent) : QWidget(parent) {
       img = QImage("Sample.jpg");     // The image to paint
       mask = QImage("Mask.png");      // An indexed 2-bit colormap image
       QPainter imgPainter(&img);
       imgPainter.drawImage(0, 0, mask);  // Paint the mask onto the image
    }
    
    void MaskWidget::paintEvent ( QPaintEvent * event ) {
       QPainter painter(this);
       painter.drawImage(10, 10, img);
    }
    

    Mask.png is an image file with the same size as Sample.jpg. It contains an alpha channel to support transparency. You can create this file easily with The GIMP, for example. I added an alpha channel, changed all areas I want to have painted to transparent and all other areas to white. To reduce the size, I finally converted it to an indexed 2-bit image.
    You could even create the mask image programmatically with Qt, if you need your triangle be computed based on various parameters.

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

Sidebar

Related Questions

I need something similar to the Silverlight InkPresenter , that allows a freehand drawing
I need something similar to String.format(...) method, but with lazy evaluation. This lazyFormat method
I came across JGo Java library. I need something similar but for free and
From what I see there's no command for this, but I need something similar
Is there a URL encoding function in XSLT version 1? I need something similar
I need to build a Windows control that displays KPI indicators. Something similar to
I need something simple like date , but in seconds since 1970 instead of
I need something like this http://jonraasch.com/blog/a-simple-jquery-slideshow but w/o the absolute positioning. Is it possible?
I need something similar to List<String, Int32, Int32> . List only supports one type
I need something similar to TAnimate in Delphi win32 for Delphi Prism for .NET.

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.