How to Create Custom Shaped Windows in Qt

By default every window you create has a rectangular shape but in case you want to have a window which is non-rectangular (such as ellipse or triangle or any shape you prefer) then you can use the approach below.

In this example I’ll create an ellipse window (as seen below) but the approach is correct in case of any other shape you want.

2016-03-10


First you need to create a QRegion. This is in fact the region that you want to remain visible. So I am going to create an ellipse region which has the same width and height as the window itself using the following code:

QRegion region(rect(), QRegion::Ellipse);

Simple right?!

Next you apply this QRegion to your Window’s mask using the following code and it’s done:

setMask(region);

Note that you have to write both of these lines in your window’s constructor function.

One more this to note is that you can in fact apply a QBitmap, that is a bitmap that you have created, to the setMask function above and you can have Windows with any other shapes.



3 Replies to “How to Create Custom Shaped Windows in Qt”

    1. Unfortunately not possible with the method described here in this post. You’ll need to look for a method to apply masks with an alpha-channel to windows as opposed to 1-bit depth masks like QBitmap

      1. Could you check email. I have requested a tutorial suggestion on Qt Qrcode with an example. Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.