Last active
October 6, 2021 14:27
-
-
Save Pikachuxxxx/c16ddb7c5150999c8fa4947361fe014d to your computer and use it in GitHub Desktop.
A small snippet to render a rounded QT main window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void resizeEvent(QResizeEvent* event) | |
{ | |
QImage image(this->size(), QImage::Format_Mono); | |
image.fill(0); | |
int roundness = 20; | |
if (!this->isFullScreen() && !this->isMaximized()) { | |
//image.setPixel(0, 0, 1); image.setPixel(1, 0, 1); image.setPixel(2, 0, 1); image.setPixel(3, 0, 1); image.setPixel(4, 0, 1); image.setPixel(5, 0, 1); image.setPixel(6, 0, 1); | |
//image.setPixel(0, 1, 1); image.setPixel(1, 1, 1); image.setPixel(2, 1, 1); image.setPixel(3, 1, 1); image.setPixel(4, 1, 1); | |
//image.setPixel(0, 2, 1); image.setPixel(1, 2, 1); image.setPixel(2, 2, 1); | |
//image.setPixel(0, 3, 1); image.setPixel(1, 3, 1); image.setPixel(2, 3, 1); | |
//image.setPixel(0, 4, 1); | |
//image.setPixel(0, 5, 1); | |
for (int x = 0; x < roundness; x++) | |
{ | |
for (int y = 0; y < roundness; y++) { | |
// Remove the pixels along the border | |
if(x == 0 || y == 0) | |
image.setPixel(x, y, 1); | |
// Remove the pixel if it lies outside of the circle at x, y and in the second quadrant of the circle | |
if((x <= roundness && y <= roundness) && (sqrt(pow((double) roundness - x, 2) + pow((double) roundness - y, 2))) >= roundness) | |
image.setPixel(x, y, 1); | |
} | |
} | |
} | |
this->setMask(QPixmap::fromImage(image)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment